同时采用JSeperator不寻常的差距 - 的Java [英] Unusual gaps while using JSeperator - Java
问题描述
我一直在一个Swing GUI和加入 JSeperator
,不知道如何删除后得到一些不寻常的和不需要的差距?或任何其他选项,如何实现这个很好!
I have been working on a Swing GUI and getting some unusual and unwanted gaps after adding JSeperator
, Any idea how to remove them? Or any other option to how to achieve this nicely!
视觉描述
之前的差距是显而易见的的JLabel
生死时速之后 JSlider的
。
Gaps are apparent before JLabel
"Speed" and after JSlider
.
相关code
control.setLayout(new BoxLayout(control, BoxLayout.X_AXIS));
...another code omitted...
control.add(orientation); //JLabel
control.add(norm); //JRadioButton
control.add(back); //JRadioButton
control.add(new JSeparator(SwingConstants.VERTICAL));
control.add(speedLabel); //JLabel
control.add(speed); //JSlider
control.add(new JSeparator(SwingConstants.VERTICAL));
control.add(turnOutLabel); //JLabel
control.add(right); //JRadioButton
control.add(straight); //JRadioButton
control.add(left); //JRadioButton
我想是有拥有一切中心和JSeperator分离,
What I want is to Have have everything centred and separated by JSeperator,
视觉描述
感谢您。
推荐答案
只需更换 JSeparator的新(...)
通过下面的代码(你可以把它们放在一个方法如果你想):
Just replace new JSeparator(...)
with the following lines (you can put them in a method if you want):
JSeparator separator = new JSeparator(JSeparator.VERTICAL);
Dimension size = new Dimension(
separator.getPreferredSize().width,
separator.getMaximumSize().height);
separator.setMaximumSize(size);
由于@kleopatra解释,有JSeparator的无界最大尺寸(在两个方向),所以这里的技巧是限制最大宽度为preferred宽度,但仍保持最大高度保持不变(因为preferred高度 0
)。
这篇关于同时采用JSeperator不寻常的差距 - 的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!