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!!
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 ]
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.
Joined: Feb 20, 2004
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.
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 ]
Write once, run anywhere, because there's nowhere to hide! - /. A.C.