[英]how can I define label position of a jRadioButton on Netbeans?
我想在Netbeans上的buttonGroup上定义jRadioButtons的标签位置,以便标签位于其radioButton下。 可以吗?
将JRadioButton#setText()
与setVerticalTextPosition(SwingConstants.BOTTOM)
。
JRadioButton jrb = new JRadioButton();
jrb.setText("Label");
jrb.setVerticalTextPosition(JRadioButton.BOTTOM);
jrb.setHorizontalTextPosition(JRadioButton.CENTER);
你必须同时使用r.setVerticalTextPosition(JRadioButton.BOTTOM);
和r.setHorizontalTextPosition(JRadioButton.CENTER);
一起。 否则,它将无法正常工作
import javax.swing.*;
import java.awt.*;
public class PersonFrame extends JFrame
{
public PersonFrame()
{
JRadioButton r = new JRadioButton();
r.setText("Text");
r.setVerticalTextPosition(JRadioButton.BOTTOM);
r.setHorizontalTextPosition(JRadioButton.CENTER);
JPanel testPanel = new JPanel();
testPanel.setLayout(new FlowLayout());
testPanel.add(r);
this.add(testPanel);
this.setSize(100,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[]args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run() {
new PersonFrame();
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.