[英]Unable to vertically align JLabel with JCheckBox as if single JCheckBox with GroupLayout
Sometimes I need the label for a checkbox to be to the left of the checkbox not the right so instead of using 有时,我需要复选框的标签位于复选框的左侧而不是右侧,所以不要使用
JCheckBox checkbox = new JCheckBox("label",false);
I do: 我做:
JCheckBox checkbox = new JCheckBox("",false);
JLabel label = new JLabel("label");
GroupLayout.ParallelGroup vp1 = layout.createBaselineGroup(false, false);
vp1.addComponent(checkbox);
vp1.addComponent(label);
(I am using GroupLayout) but they are not vertically aligned correctly, I've also tried (我正在使用GroupLayout),但它们未正确垂直对齐,我也尝试过
=layout.createParallelGroup(GroupLayout.Alignment.CENTER);
which doesn't look bad but still appears different to using a single checkbox and various other options, is it possible to get the same alignment ? 哪个看起来不错,但仍然看起来与使用单个复选框和其他各种选项有所不同,是否有可能获得相同的对齐方式?
您可以将函数setHorizontalTextPosition(int textPosition)
与int值SwingConstants.RIGHT
等一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.