• 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

Help Me Click the Default Button

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've got a popup control to capture a password. However, I can't get the 'OK' button to be the default button such that when I type in a password and hit enter, the OK button would be clicked. Instead, I have to tab out and hit space, or I have to click it with the mouse button.
I've tried many combinations. The most recent attempt (listed, below) is to capture the VK_ENTER, move focus to the next control (the 'OK' button), and press the space key.
I must be doing something wrong, though. I get the focus to move forward, but no luck with clicking the space.
Any help is greatly appreciated!!

[ February 20, 2004: Message edited by: Tim E. ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add an ActionListener to a JPasswordField. So something like....

You don't have to pass the ActionEvent to your loginAction method if you don't want to. Only if you need access to that object.
Another thing you can try which I can't get to work 100% of the time is:
getRootPane().setDefaultButton(submitButton);
Sometimes this works for me, other times it doesn't. That's why I usually just do it the first way I suggested. It works all the time.
[ February 20, 2004: Message edited by: Gregg Bolinger ]
 
T Eakins
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help.
Unfortunately, I don't have the submitButton handle because I am using the java's standard modal dialog boxes:

Maybe it just can't be done without creating my own dialog box. Any other thoughts?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, ShowInputDialog() does what you want. Problem with that is I don't know of a way to specify a JPasswordField so your input wouldn't be masked. The only way to do what you want is to write a custom dialog by extending JDialog.
 
T Eakins
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I've tried a lot of different approaches and I didn't see a way, either. That seemed like something that should be available because I could envision a scenario where I needed to add some other type of ActionListener to the OK button before processing.
Thanks again for your help. I'll write a small custom dialog box to force it.
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How strange that this isn't supported...
What JDK version?
Have you looked at the source for JOptionPane to see if it attempts such functionality?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's how I got it to work... the only issue I would like to fix would be how to get the username field to be the initial selection when the optionpane comes up. I tried adding a component listener to the panel and to the username text field, but neither worked...



(NEP - removed long line in code that was widening the page )
[ February 24, 2004: Message edited by: Nathan Pruett ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this is why Nathan is the king!
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice example Nathan!
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic