【问题标题】:Java: How do I change the font size of a JRadioButton?Java:如何更改 JRadioButton 的字体大小?
【发布时间】:2015-09-22 18:36:36
【问题描述】:

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

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

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

这是我的代码的 sn-p...

    // 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

【问题讨论】:

    标签: java radio-button


    【解决方案1】:

    你已经做到了。 您希望标签具有与 Jlabel right 相同的字体大小。然后你可以简单地做到这一点

     q1a1.setFont(q1.getFont()); //assign the label's font to radiobutton's font
    

    或者按照你对标签所做的相同方式进行操作

      q1a1.setFont(q1a1.getFont().deriveFont(24.0f)); 
    

    【讨论】:

      猜你喜欢
      • 2011-02-04
      • 1970-01-01
      • 2011-08-31
      • 2019-02-19
      • 2011-09-24
      • 2015-12-09
      • 2012-10-27
      • 2015-02-05
      • 1970-01-01
      相关资源
      最近更新 更多