I have a GUI build with Java's Swing. I have a JPanel that holds all of my controls:
JPanel rightSidePanel = new JPanel(new GridBagLayout());
rightSidePanel.add(forwardKinematics, new GridBagConstraints());
This works fine. However, I would like to add a tabbed control. Unfortunately, adding the tabs breaks the layout:
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Forward Kinematics", forwardKinematics);
JPanel rightSidePanel = new JPanel(new GridBagLayout());
rightSidePanel.add(tabs, new GridBagConstraints());
Now, some of the controls in forwardKinematics
are horribly crunched up, instead of expanding to their full size. Is there some way that I'm supposed to specify the controls can expand and take up as much space as they want?
I'm using gridbag layouts.
Here is the code that creates the UI controls that get squished (with irrelevant excerpts removed):
panel.add(label, new GridBagConstraints());
GridBagConstraints gbc = new GridBagConstraints();
final DefaultTableModel model = new DefaultTableModel();
model.addColumn("foo");
model.addColumn("bar");
final JTable table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
gbc = new GridBagConstraints();
gbc.gridy = 2;
gbc.ipady = 10;
gbc.ipadx = 10;
panel.add(scrollPane, gbc);
final JComboBox comboBox = new JComboBox();
gbc = new GridBagConstraints();
gbc.gridy = 1;
panel.add(comboBox, gbc);
JButton makeNewButton = new JButton("Make new from current state");
gbc = new GridBagConstraints();
gbc.gridy = 1;
panel.add(makeNewButton, gbc);
JButton deleteButton = new JButton("Delete Current Keyframe");
gbc = new GridBagConstraints();
gbc.gridy = 2;
panel.add(deleteButton, gbc);
JButton playAll = new JButton("Play All");
gbc = new GridBagConstraints();
gbc.gridy = 2;
panel.add(playAll, gbc);
What am I doing wrong here?
Update: I tried using tabs.setPreferredSize()
. That makes the area surrounding the tab bigger (as if I'm adding padding), but the content within them stays squished as ever.