我想实现这种外观并尝试相应地设置 JPanel 组件,但当我运行应用程序时,我看到了不同的位置。这就是我正在寻找的外观:
首先,顺序不正确,其次,项目之间没有空格,所以总的来说,这不是我想要的。如何修复它以使其看起来与我第一次添加的图像相似?我的代码:
package Lab5;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
public class FontDesigner extends JFrame {
public FontDesigner() {
// JFrame
setSize(400, 400);
setTitle("Font Changer");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// String
JLabel text = new JLabel("Change Me");
text.setFont(new Font("Arial", 1, 28));
// Radio Button
JRadioButton button1 = new JRadioButton("Small");
JRadioButton button2 = new JRadioButton("Medium");
JRadioButton button3 = new JRadioButton("Large");
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(button1);
radioGroup.add(button2);
radioGroup.add(button3);
/*
* if (button1.isSelected()) {
* text.setSize(1);
* }
*/
// Combo Box …Run Code Online (Sandbox Code Playgroud)