我在我的表单上使用 SpringLayout,但是正如你所看到的,它的外观并不好(大而坏的尺寸)!
public class t8 extends JFrame {
JButton okButton, cancellButton;
JTextField idTF, nameTf;
JLabel idlbl, namelbl;
public t8() {
add(createPanel(), BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 500);
setLocation(400, 100);
setVisible(true);
}
public static void main(String[] args) {
new t8();
}
public JPanel createPanel() {
JPanel panel = new JPanel();
okButton = new JButton("Ok");
cancellButton = new JButton("Cancel");
idTF = new JTextField(10);
nameTf = new JTextField(10);
idlbl = new JLabel("ID");
namelbl = new JLabel("Name");
panel.add(idlbl);
panel.add(idTF);
panel.add(namelbl);
panel.add(nameTf);
panel.add(okButton);
panel.add(cancellButton);
panel.setLayout(new SpringLayout());
SpringUtilities.makeCompactGrid(panel, 3, 2, 20, 50, 50, 100);
return panel;
}
}
我改变makeCompactGrid
了数字,但没有成功!
(宽度JTextFields
很大,我的按钮大小不一样)