I am trying to add two scroll pane along with one label and one button in a JPanel using GridBagLayout. While the first scroll pane containing a JList and the second scroll pane containing a JTable. Below is the code:
JPanel capabilityPanel = new JPanel(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
JScrollPane capabilityScrollPane = new JScrollPane(cbList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JScrollPane capabilityTableScrollPane = new JScrollPane(table,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JButton saveButton = new JButton("Save Table Values");
JLabel capabilityLabel = new JLabel("Boolean Capability List");
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 0;
capabilityPanel.add(capabilityLabel, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
capabilityPanel.add(capabilityScrollPane,constraints);
constraints.gridx = 0;
constraints.gridy = 1;
capabilityPanel.add(saveButton, constraints);
constraints.gridx = 1;
constraints.gridy = 1;
capabilityPanel.add(capabilityTableScrollPane, constraints);
The problem is when I am directly adding the table in the panel instead of the corresponding scroll pane, it is displaying properly on the screen. But when I am adding the scroll pane, only three element is displayed, table is not showing at all. I want the table to be shown with scroll.
Can you please help me with this situation?
It will create one outerpanel
two inner panel
One for list
One for table
Layout
package newpackage;
Output