Java 将按钮添加到spring布局
我一直在尝试向使用SpringLayout构建的表单添加两个按钮 我似乎不知道如何在表单底部添加按钮。我试过几种方法,但似乎不管用 主要方法如下:Java 将按钮添加到spring布局,java,forms,button,user-interface,springlayout,Java,Forms,Button,User Interface,Springlayout,我一直在尝试向使用SpringLayout构建的表单添加两个按钮 我似乎不知道如何在表单底部添加按钮。我试过几种方法,但似乎不管用 主要方法如下: private static void createAndShowGUI() { String[] labels = {"Name: ", "Fax: ", "Email: ", "Address: ", "Test: "}; int numPairs = labels.length; JFrame frame = new
private static void createAndShowGUI() {
String[] labels = {"Name: ", "Fax: ", "Email: ", "Address: ", "Test: "};
int numPairs = labels.length;
JFrame frame = new JFrame("SpringForm");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and populate the panel.
JPanel p = new JPanel(new SpringLayout());
for (int i = 0; i < numPairs; i++) {
JLabel l = new JLabel(labels[i], JLabel.TRAILING);
p.add(l);
JTextField textField = new JTextField(10);
l.setLabelFor(textField);
p.add(textField);
}
//Set up the content pane.
Container contentPane = frame.getContentPane();
contentPane.setLayout(new SpringLayout());
//Add the buttons.
contentPane.add(new JButton("Button 1"));
contentPane.add(new JButton("Button 2"));
//Lay out the panel.
SpringUtilities.makeCompactGrid(p,
numPairs, 2, //rows, cols
6, 6, //initX, initY
6, 6);
//Set up the content pane.
p.setOpaque(true); //content panes must be opaque
frame.setContentPane(p);
//Display the window.
frame.pack();
frame.setVisible(true);
}
private static void createAndShowGUI(){
字符串[]标签={“名称:”、“传真:”、“电子邮件:”、“地址:”、“测试:”};
int numPairs=labels.length;
JFrame框架=新JFrame(“SpringForm”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//创建并填充面板。
JPanel p=newjpanel(newspringlayout());
for(int i=0;i
非常感谢您的帮助。请阅读我所做的。事实上,上面的代码取自其中一个示例。它们对表单和按钮都有单独的示例。我只是想把这两者结合起来,但不知道怎么做。