不能 Java GUI 看起来像我想要的那样...?
Can't Java GUI to look the way I want...?
问题只是希望 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]
您总共显示了 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
问题只是希望 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]
您总共显示了 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