my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Setting  hot keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting  hot keys" Watch "Setting  hot keys" New topic
Author

Setting hot keys

Meena Pitchiah
Greenhorn

Joined: Apr 24, 2003
Posts: 16
Hi,
I am using setMnemonic() to set short cut key to buttons and using SystemLookandFeel.
In Windows system, it does not underline the hot keys when loaded. After pressing Alt key once, everything seems to work fine ( all the hot keys are underlined and pressing the hot key fires the button's action event.
Can anyone faced similar problem. Any suggestion please?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi Meena,
Yes, this is the default behaviour for Windows XP and 2000. I believe you can change this behaviour via some Windows configuration option(s) -- but I don't remember how.
Alternatively, the following code (which I found in the "comp.lang.java.programmer" newsgroup) works for me:

Good Luck,
Avi.
Meena Pitchiah
Greenhorn

Joined: Apr 24, 2003
Posts: 16
Hi Avi,
Thank you so much. It works now. Can you please clarify one more problem?
How can I get focus on some JtextField on window load. In a Dialog, I have JTabbedPane and two tabs. At the time of load, I need to select the first tab and place the cursor on the first entry field of that tab. I tried component.requestFocus, pane.requestFocus() (here the pane is the JPanel that contains the entry field). Also tried component.requestFocus() in windowOpened() of WindowListener. Nothing works. The focus is on the first tab when it is loaded.
The requestFocus() works fine inside stateChanged() of ChangeEvent. So if I select the second tab and come back to the first one, the focus is on the entry field.
Thanks
Meena
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Meena,
I'm terribly sorry, I only just saw your post now.
Yes, in order for the "JTextField" to get the initial focus, I use

and I put the call to "requestFocus()" in the "windowOpened()" method of the "WindowListener" interface. However, I believe (although I haven't tried it) that the "JTextField" needs to be in the 'selected' tab of the "JTabbedPane", so perhaps, before calling "requestFocus()" you need to select the tab (of the "JTabbedPane") that contains the "JTextField" you want to get the focus. You can use the "setSelectedIndex()" method (in class "JTabbedPane") to do this.
Good Luck,
Avi.
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
Try with FocusTraversalPolicy. For any information, see here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting hot keys
 
Similar Threads
GUI is messed up in sun Solaris
setting hot keys
Multithreading for Event Handling
Multithreading for Event Handling
setMnemonic