Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple way to implement a dialog box with two input lines? (java)

I'm making an xml editor as one of our projects in class, and for adding 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 just a single dialog box with both those things on it? I looked at some examples but I am having trouble implementing/understanding them. While I am able to correctly add attributes with the current method, it is kind of silly to have two input boxes.

Please let me know if there is some simple solution to this. Thanks

like image 295
Chea Indian Avatar asked Dec 06 '22 13:12

Chea Indian


1 Answers

Yes, you can create a JPanel that holds two JTextFields and pop that into a JOtionPane.showConfirmDialog(....), and then when it returns, if the user presses the OK button, extract the text from the JTextFields.

For instance, please check out my code in this answer

like image 174
Hovercraft Full Of Eels Avatar answered Dec 09 '22 02:12

Hovercraft Full Of Eels