I wonder if it's possible to have several input fields i the JOptionPane in Java, instead of one like in开发者_JAVA技巧 the code below?
String info = JOptionPane.showInputDialog("Name?");
Something like this...
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class OptionPaneTest {
public static void main(String[] args) {
JPanel myPanel = new JPanel();
JTextField field1 = new JTextField(10);
JTextField field2 = new JTextField(10);
myPanel.add(field1);
myPanel.add(field2);
JOptionPane.showMessageDialog(null, myPanel);
System.out.println(field1.getText() + field2.getText());
}
}
Yes, you can in fact show a very complex GUI with JLabels, JButtons, JTextFields, JTextAreas, and all sorts of other goodies, all displayed in a simple to call JOptionPane. I don't think I'd use the showInputDialog(...)
method for this though.
精彩评论