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?
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.
Joined: Apr 24, 2003
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
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.