开发者

Several input fields with JOptionPane?

开发者 https://www.devze.com 2023-04-13 09:01 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号