Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java/Swing Box Layout with Separator

Here is the code:

Box twoPanelBox= new Box(BoxLayout.Y_AXIS);
twoPanelBox.add(panelA); // red
twoPanelBox.add(new JSeparator(SwingConstants.HORIZONTAL) );
twoPanelBox.add(panelB); // black

And here is what i get:

screenshot of panels

The red and the black panel are displayed as expected, where the seperater ( green box around) has something like a margin between.

How can a avoid this marging, and eliminate this space (grey area)? Thank you

like image 364
MemLeak Avatar asked Dec 27 '13 14:12

MemLeak


1 Answers

A little unexpectedly, BoxLayout will stretch the separator. However, this dirty hack will help:

JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
separator.setMaximumSize( new Dimension(Integer.MAX_VALUE, 1) );
mergeBox.add(separator);
like image 142
MemLeak Avatar answered Nov 15 '22 04:11

MemLeak