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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With