I am new to Java Swing and I am trying to create an application.
I have a MainApplication.java file which extends SingleFrameApplication and where I am creating a JPanel named MainPanel. This MainPanel has an AnimatingSplitPane with VERTICAL_SPLIT named SplitPane.
On the Top of the SplitPane, I am adding another JPanel named MainContainer. On the bottom of the SplitPane, I am adding a JPanel named FormContainer. The MainContainer loads the another class named DataSheetTable (a JPanel having JTable).
Now, when user clicks on the cells of the DataSheetTable, I want to load the form into the FormContainer. I don’t know, how can I achieve this.
For instance, DatasheetTable has Column1, Column2 and Column3. When user clicks on any cell of Column1, I need to show Form1 into the FormContanier. If it clicks on Column2 cell then I need to show Form2 into FormContanier.
Please let me know with some sample code, how can I achieve loading the forms on the fly to FormContainer.
![Thank you in advance.]
Image description for the issue
Here is sample code for App.java
public class App extends SingleFrameApplication {
@Override protected void startup() {
configureDefaults();
View view = getMainView();
view.setComponent(createMainPanel());
show(view);
}
protected JComponent createMainPanel() {
// Create main panel with demo selection on left and demo/source on right
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
// Create splitpane on right to hold demo and source code
splitPane = new AnimatingSplitPane(JSplitPane.VERTICAL_SPLIT);
mainPanel.add(splitPane, BorderLayout.CENTER);
// Create panel to contain main panel
mainContainer = new JPanel();
splitPane.setTopComponent(mainContainer);
DataSheetTable dataSheetTable = new DataSheetTable();
mainContainer.add(dataSheetTable, BorderLayout.CENTER);
dataSheetTable.start();
formContainer = new JPanel(new BorderLayout());
splitPane.setBottomComponent(formContainer);
formContainer.add(new OrganizationForm());
return mainPanel;
}
}
Here is sample code for DataSheetTable.java file
public class DataSheetTable extends JPanel {
........
controlPanel = createControlPanel();
add(controlPanel, BorderLayout.NORTH);
routingTable = new JTable(routingModel);
.........
}
So here is your code for intercepting events of table cell clicks:
EDIT
Looking at your update: Just add to
DataSheetTableconstructor reference to yourFormContainer:and in
DataSheetTableadd listener: