我想在Netbeans上的buttonGroup上定义jRadioButtons的标签位置,因此标签将位于其radioButton下。可以吗?
答案 0 :(得分:5)
将JRadioButton#setText()
与setVerticalTextPosition(SwingConstants.BOTTOM)
一起使用。
JRadioButton jrb = new JRadioButton();
jrb.setText("Label");
jrb.setVerticalTextPosition(JRadioButton.BOTTOM);
jrb.setHorizontalTextPosition(JRadioButton.CENTER);
答案 1 :(得分:2)
您必须同时使用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();
}
});
}
}