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

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top