views:

271

answers:

4

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.

+1  A: 

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.

Emil H
+1  A: 

showInputMessageDialog and its brethren are simple ways to whip up a simple "standard" dialog. For more complicated dialogs, I'm pretty sure you'll have to subclass JDialog or such.

Carl Smotricz
+3  A: 

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

}
Telcontar
Reformatted code; please revert if incorrect.
trashgod
+1  A: 

As Telcontar has suggested you can add Swing components (like a JPanel) to an option pane. So it is easy to take advantage of the automatic creation of buttons rather than do it from scratch by building your own JDialog.

However, there is one small problem. The focus will be on the first button, not on the first component of your panel. To get around this problem you can try the solution presented in Dialog Focus.

camickr