devoured elysium
devoured elysium

Reputation: 105097

Having cells with different, independent widths for the same column in MigLayout?

I'm currently facing the problem that, having 2 rows, MigLayout seems to force both first cells to have the same width, while I'd like them to work independently (notice how the "Filter" label is way too long):

enter image description here

Is there any way of avoiding that other than defining the two rows to be two different MigLayout panels?

Here's the code:

setLayout(new MigLayout("insets 15, fill", "[][grow]", "[][grow]"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setMinimumSize(new Dimension(500, 400));

add(new JLabel("Filter:"));
add(new JTextField(), "wrap, growx");

add(new JScrollPane(new JTree()), "width 200, growy");
add(new JScrollPane(new JTable()), "span 2, grow");

pack();
setLocationRelativeTo(null);
setVisible(true);

Thanks

Upvotes: 1

Views: 65

Answers (1)

Dan
Dan

Reputation: 7724

There is a simple trick with MigLayout where you can split a cell and tell that single cell to span. In your case, you would do this on the JLabel.

add(new JLabel("Filter:"), "split, span");

enter image description here

Upvotes: 1

Related Questions