Reputation: 13486
I am trying to add a JTabbedPane
to a panel, with buttons above it for controls. I am using MigLayout.
But, I cannot get the JTabbedPane
to fill without the buttons also filling when they don't need to.
Take the following SSCCE:
public static void main(String[] args) {
JPanel panel = new JPanel(new MigLayout(new LC().fill()));
panel.add(new JButton("+"));
panel.add(new JButton("-"), "wrap");
panel.add(new JTabbedPane(), "span, grow");
JFrame frame = new JFrame();
frame.add(panel);
frame.setSize(new Dimension(300, 500));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
This produces a panel that looks like this:
But, if I remove fill()
from the layout constraints (JPanel panel = new JPanel(new MigLayout(new LC()));
), it looks like this:
How do I make the JTabbedPane
to fill the content area while the JButton
s do not fill?
Upvotes: 2
Views: 1043
Reputation: 51525
If you don't want a constraint be applied to all cells, don't tell the Layout ;-) Instead, use column and row constraints: three columns and let only the last fill and grow and two rows with the last growing
JPanel panel = new JPanel(new MigLayout("", "[][][fill, grow]", "[][fill, grow]"));
panel.add(new JButton("+"));
panel.add(new JButton("-"), "wrap");
panel.add(new JTabbedPane(), "span, grow");
Upvotes: 4