简体   繁体   English

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

[英]Java: How do I change the font size of a JRadioButton?

How do I change the font size of a JRadioButton (in Java)? 如何更改JRadioButton的字体大小(在Java中)? I just want to make the text 24px instead of the default so that it matches the label. 我只想将文本设置为24px而不是默认值,以使其与标签匹配。

Here's a link to a picture of my window... (I don't have enough reputation to post the image directly...) 这是我窗口图片的链接...(我没有足够的声誉直接发布图片...)

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

And here's a snippet of my code... 这是我的代码的一部分...

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

Thanks in advance! 提前致谢!

-HewwoCraziness -疯狂疯狂

You've already done it. 您已经完成了。 You want the label to have as same font size as Jlabel right. 您希望标签具有与Jlabel right相同的字体大小。 Then you can simply do that by 然后,您可以简单地通过

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

or do the same way you've done it for label 或使用与标签相同的方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM