我一直在尝试使用任何布局管理器类来垂直排列GUI元素,但一切都无济于事。我实际上想要多个课程作为输入,以便能够创建垂直排列的jtextfield的数量,仍然会是为其他三列放置文本框的空间..谢谢,这是下面的代码:
new GPA_Calculator().setVisible(false);
String a = JOptionPane.showInputDialog("Enter the number of courses");
Integer b = Integer.parseInt(a);
final int FRAME_WIDTH = 400;
final int FRAME_HEIGHT = 400;
JFrame aFrame = new JFrame("GPA Calculator");
aFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
aFrame.setVisible(true);
aFrame.setResizable(false);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel ();
aFrame.add(panel);
GridLayout grid = new GridLayout (b,4);
panel.setLayout(grid);
for (int counter = 0; counter < b; counter++)
{
JTextField textfield = new JTextField(5);
panel.setBackground(Color.GREEN);
panel.add(textfield);