• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add JtextField to JOptionPane

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic