Java:如何更改JRadioButton的字体大小?

时间:2015-07-05 15:20:26

标签: java radio-button

如何更改JRadioButton的字体大小(在Java中)? 我只想将文本设置为24px而不是默认值,以便它与标签匹配。

这是我窗口图片的链接...... (我没有足够的声誉来直接发布图片......)

http://i.stack.imgur.com/z60kN.png

这是我的代码片段......

    // question 1: make the labels / radio buttons / buttons / rows
    JLabel q1 = new JLabel("Question 1: 2 + 4");
    q1.setFont (q1.getFont ().deriveFont (24.0f));
    final JRadioButton q1a1 = new JRadioButton("5");
    final JRadioButton q1a2 = new JRadioButton("6");
    final JRadioButton q1a3 = new JRadioButton("7");
    final JRadioButton q1a4 = new JRadioButton("8");
    JButton q1go = new JButton("Go");
    JButton q1exit = new JButton("Exit");
    JPanel question = new JPanel();
    JPanel answers = new JPanel();
    JPanel buttons = new JPanel();
    question.setLayout(new BoxLayout(question, BoxLayout.X_AXIS));
    answers.setLayout(new BoxLayout(answers, BoxLayout.Y_AXIS));
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));

    // add everything to the rows
    question.add(q1);
    answers.add(q1a1);
    answers.add(q1a2);
    answers.add(q1a3);
    answers.add(q1a4);
    buttons.add(q1go);
    buttons.add(q1exit);

    // add the rows
    add(question);
    add(answers);
    add(answers);
    add(answers);
    add(answers);
    add(buttons);

    // group the radio buttons
    ButtonGroup group = new ButtonGroup();
    group.add(q1a1);
    group.add(q1a2);
    group.add(q1a3);
    group.add(q1a4);

提前致谢!

-HewwoCraziness

1 个答案:

答案 0 :(得分:0)

你已经完成了。 您希望标签具有与Jlabel相同的字体大小。然后你可以通过

简单地做到这一点
 q1a1.setFont(q1.getFont()); //assign the label's font to radiobutton's font

或以与标签

相同的方式进行操作
  q1a1.setFont(q1a1.getFont().deriveFont(24.0f)); 
相关问题