我只是想在 java swing 中向 GridBagLayout 添加 3 个居中的垂直按钮。现在我相信默认的网格大小是 3x3。我想知道我是否可以改变它并添加更多的列和行。我只是想在一个窗格中制作 3 个居中的等距按钮。
pane.setLayout(new GridLayout(10,1));
// Insert a space before the first button
for (int i = 1; i < 6; i++ ){
pane.add(new JLabel(""));
}
pane.add(new Button("1"));
pane.add(new Button("2"));
pane.add(new Button("3"));
// Insert a space after the last button
pane.add(new JLabel(""));
这是最终的解决方案谢谢大家!