wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to add JtextField to JOptionPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add JtextField to JOptionPane" Watch "How to add JtextField to JOptionPane" New topic
Author

How to add JtextField to JOptionPane

Harsha Jay
Ranch Hand

Joined: Jul 23, 2001
Posts: 177
Hello ,
I am trying to add a listener to the JtextField instance and pass this to a JOptionPane.showOptionDialog(.....) method
How do I do this ?
A small code snippet would greatly help
Harsha
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

What listener are you trying to put on the JTextField?
If you don't have any other options, JOptionPane's great-grandparent is java.awt.Container, and Container has a getComponents() method.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Harsha Jay
Ranch Hand

Joined: Jul 23, 2001
Posts: 177
I am trying to add a mouselistener to the JTextField and pass this Object as an parameter to

method.

This way when a right click is sensed on the textfield Object, I can do the processing like show a right-click-PopUp...
Does this make sense???
pl reply
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by Harsha Jay:

Does this make sense???

Nope. That constructor is ment to create a drop-down list of selections from the Object array, with the last Object parameter selected.
Harsha Jay
Ranch Hand

Joined: Jul 23, 2001
Posts: 177
sun javadocs say :-

showInputDialog
public static Object showInputDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon,
Object[] selectionValues,
Object initialSelectionValue)
throws HeadlessExceptionPrompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified. The user will able to choose from selectionValues, <b><i>where null implies the user can input whatever they wish, usually by means of a JTextField.</i></b>
initialSelectionValue is the initial value to prompt the user with. It is up to the UI to decide how best to represent the selectionValues, but usually a JComboBox, JList, or JTextField will be used.

The one in Bold says we can use Jtextfield....
How do I use JTextfield for the showInputdialog method in JOptionPane?
Thanks again
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

The documentation says that when the selection array is null, the JOptionPane will USUALLY display a JTextField, but there is no way to either 1. guarantee that it will display a JTextField or 2. pass a JTextField in to be displayed.
How about extending JDialog and putting whatever you want on it with whatever listeners you want?
Harsha Jay
Ranch Hand

Joined: Jul 23, 2001
Posts: 177
If you do not mind can you just give me something to start... on JDialog...
how to create a JDialog and the grab the text from the JDialog.. to my processing routines.
thank you Joe for the previous reply!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to add JtextField to JOptionPane
 
Similar Threads
System Date
Problems with Jtable and JTextField Binding
how to search in a JComboBox
JTextField problem
JTextField