问题只是希望GUI看起来像这样:
这是我的代码
import javax.swing.JOptionPane;
class Customer
{
String n = JOptionPane.showInputDialog("Enter name");
String id = JOptionPane.showInputDialog("Enter id");
String sub = JOptionPane.showInputDialog("Enter Submit");
JOptionPane.showMessageDialog(null, null, null, JOptionPane.PLAIN_MESSAGE)
}
}
我希望一切看起来都是水平的
Enter Name [box to fill in name]
Enter id [box to fill in id]
Submit [box to enter submit]
答案 0 :(得分:2)
您将共显示4个选项窗格。如果您想要一个选项窗格中的所有内容,这可能会有所帮助:
JPanel msgPanel = new JPanel();
msgPanel.setLayout(new GridLayout(3 , 2));
msgPanel.add(new JLabel("Enter name");
JTextField nameField = new JTextField();
msgPanel.add(nameField);
//create other fields and labels
JOptionPane.showMessageDialog(null , msgPanel , "" , JOptionPane.PLAIN_MESSAGE);
String name = nameField.getText();
//read other fields