Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get JOptionPane with three text fields

I want to know how i can do a messageBox from three input dialog ..

Like this:

JOptionPane.showInputMessageDialog("Enter your FirstName");
JOptionPane.showInputMessageDialog("Enter your MiddleName");
JOptionPane.showInputMessageDialog("Enter your LastName");

But I want one message has a three input boxes.

like image 982
Dr.Mostafa Avatar asked Apr 28 '10 13:04

Dr.Mostafa


People also ask

What is JOptionPane showMessageDialog?

It is used to create an information-message dialog titled "Message". static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) It is used to create a message dialog with given title and messageType.


2 Answers

Build a JPanel (supose it's named inputPanel) with the three JtextFields to input and then do this:

if (JOptionPane.YES_OPTION == JOptionPane.showconfirmDialog(
    parentComponent, inputPanel, "Enter your data", JOptionPane.YES_NO_OPTION) {

    // retrieve data from the JTextFields and do things

} else {

    // User close the dialog, do things... or not

}
like image 69
Telcontar Avatar answered Nov 02 '22 11:11

Telcontar


You can't do that with JOptionPane. Create a JDialog and add three JTextField's to it instead. A JDialog will block the caller when you call setVisible(true), so it's easy to create a dialog that waits for user input before it returns.

like image 43
Emil H Avatar answered Nov 02 '22 12:11

Emil H