我有一个希望是这样的 jframe:
这是我的代码,但显示全屏按钮!
public class editFrame extends JFrame {
JButton saveButton;
JButton cancelButton;
public editFrame() {
Component add = this.add(createForm());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 50, 500, 600);
this.setVisible(true);
}
public JPanel createForm() {
String[] labels = {"ID", "Name", "Date", "Borrow Status"};
// Create and populate jpanel
JPanel panel = new JPanel();
for (int i = 0; i < 4; i++) {
JLabel l = new JLabel(labels[i], JLabel.TRAILING);
panel.add(l);
JTextField textField = new JTextField(10);
l.setLabelFor(textField);
panel.add(textField);
}
SpringLayout sL = new SpringLayout();
panel.setLayout(sL);
SpringUtilities.makeCompactGrid(panel, 4, 2, 6, 6, 6, 6);
return panel;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
editFrame edF = new editFrame();
}
});
}
}
我正在尝试使用弹簧布局,但现在是:
所有的 jtextfield 都这么大!!