This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

How to add JtextField to JOptionPane  RSS feed

 
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
 
Bartender
Posts: 9525
12
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: 9525
12
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: 9525
12
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
Boost this thread!