Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add JtextField to JOptionPane

 
Harsha Jay
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Harsha Jay
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic