Is there an easy way to implement a dialog with two input lines? (Java)

I am doing an xml editor as one of our projects in the class, and to add an attribute I am currently doing this:

String name = JOptionPane.showInputDialog(this, "Enter the attribute name: ", "Name", JOptionPane.INFORMATION_MESSAGE); String value = JOptionPane.showInputDialog(this, "Enter the attribute value: ", "Value", JOptionPane.INFORMATION_MESSAGE); 

Is there a better way to have only one dialog box with these things on it? I looked at some examples, but I had problems with their implementation / understanding. Although I can correctly add attributes using the current method, it's silly to have two input fields.

Please let me know if there is any simple solution. Thanks

+4
source share
2 answers

Yes, you can create a JPanel that contains two JTextFields and pop that are in JOtionPane.showConfirmDialog (....), and then when it returns, if the user clicks OK, extract the text from the JTextFields.

For example, check my code in this answer

+10
source

So you can, but you need to use the version that accepts the object (thanks hovercraft), look at Java 6 JOptionPage , there are options that accept more than one!

+5
source

All Articles