Button with user input

Hey. I want to make a button which when pressed a new panel/dialog (how is it called) will pop up with two text input fields, and two buttons ok and cancel. The user will complete the two fields and after pressing ok the values will be returned to the main programm. I have found JOptionPane but i can't find out if i can use two text input fields with this. Any help?

[376 byte] By [axelinux@hotmail.coma] at [2007-11-26 17:39:39]
# 1

> if i can use two text input fields with this

You can, but first I would suggest to use a more precise title for your post.

JOptionPane p=new JOptionPane();

JTextField tf1=new JTextField(10);

JTextField tf2=new JTextField(20);

JButton ok=new JButton("OK");

ok.addActionListener(this);

Object[] o={tf1, tf2, ok};

p.setOptions(o);

JDialog d=p.createDialog(null,"Test");

d.setVisible(true);

or create a JDialog right away.

Joerg22a at 2007-7-9 0:07:48 > top of Java-index,Desktop,Core GUI APIs...
# 2

Can I add a customized JPanel (with labels, check boxes and text fields) to array of options ? After long time of consideration, I make up this solution (this is my problem http://forum.java.sun.com/thread.jspa?threadID=5133987). I will create a JOptionPane with text fields and labels I want and then place them on JOptionPane. In catch block I'll call invokeAndWait method and in method run (of Runnable) I'll create and show dialog (This should stop executing program until user clicks on some of the button on dialog). After the user clicks on some button I'll call dispose method of dialog and retrieve values directly ftom JTextField objects. Is it good solution, is it realizable ?

Thx

paulie.xa at 2007-7-9 0:07:48 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks for the help Joerg22. :)
axelinux@hotmail.coma at 2007-7-9 0:07:49 > top of Java-index,Desktop,Core GUI APIs...