Java: 如何更改 JRadioButton 的字体大小?
Java: How do I change the font size of a JRadioButton?
如何更改 JRadioButton 的字体大小(Java)?
我只想将文本设置为 24px 而不是默认值,以便它与标签匹配。
这是我 window 的照片 link...
(我没有足够的声望直接 post 图片...)
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
你已经做到了。
您希望标签与 Jlabel right 具有相同的字体大小。然后你可以通过
简单地做到这一点
q1a1.setFont(q1.getFont()); //assign the label's font to radiobutton's font
或者按照与标签相同的方式进行操作
q1a1.setFont(q1a1.getFont().deriveFont(24.0f));
如何更改 JRadioButton 的字体大小(Java)? 我只想将文本设置为 24px 而不是默认值,以便它与标签匹配。
这是我 window 的照片 link... (我没有足够的声望直接 post 图片...)
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
你已经做到了。 您希望标签与 Jlabel right 具有相同的字体大小。然后你可以通过
简单地做到这一点 q1a1.setFont(q1.getFont()); //assign the label's font to radiobutton's font
或者按照与标签相同的方式进行操作
q1a1.setFont(q1a1.getFont().deriveFont(24.0f));