所以我应该创建一个非常简单的填充表单,如名称:______,它们应该在彼此之下,但是当我将这些JTextFields和JLabel添加到JFrame时,我得到一个空的JFrame。
JFrame frame = new JFrame("Name's Item Orders Calculator");
JPanel panel = new JPanel();
BorderLayout layout = new BorderLayout(0,2);
JTextField nameField = new JTextField(15);
JTextField numberField = new JTextField(15);
JTextField costField = new JTextField(15);
JTextField amountField = new JTextField(15);
JLabel name = new JLabel("Item Name: ");
JLabel number = new JLabel("Number of: ");
JLabel cost = new JLabel("Cost: ");
JLabel amount = new JLabel("Amount owed: ");
panel.add(name, BorderLayout.WEST);
panel.add(number, BorderLayout.WEST);
panel.add(cost, BorderLayout.WEST);
panel.add(amount, BorderLayout.WEST);
panel.add(nameField, BorderLayout.EAST);
panel.add(numberField, BorderLayout.EAST);
panel.add(costField, BorderLayout.EAST);
panel.add(amountField, BorderLayout.EAST);
/*
panel.add(new JLabel("North"), BorderLayout.WEST);
panel.add(new JLabel("Another North"), BorderLayout.WEST);
*/
frame.pack();
frame.add(panel);
frame.setLayout(layout);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);