Results 1 to 3 of 3
Thread: Maintain focus on JFrame
- 12-15-2010, 10:45 AM #1Member
- Join Date
- Dec 2010
- Rep Power
Maintain focus on JFrame
I need to invoke a JDialog on keypressing F1 to display help in my Swing application. I wrote a KeyListener for my main frame after setting the focus to it (i.e. by using myFrame.setFocusable(true) )
The problem arises that I need to be able to invoke the Help JDialog even when the current focus would be on another components in my application. Thus, unless the focus is on the main frame, which is possible only when the application is started, the KeyListener won't listen to the F1 key press. Thus, even though the current focus might be on some other component in my app, I still somehow need the focus on the main frame so that the KeyListener could be invoked.
This, to me, is tricky because I need the frame focus as soon as I hit the F1 key. Is any improvisation possible in this case?
Don't use a key listener if possible but instead use key binding. The Swing tutorials will show you how these work.
- 12-15-2010, 01:39 PM #3
- By marathaWarrior in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-02-2009, 07:35 AM
- By kuppi in forum Java AppletsReplies: 7Last Post: 11-04-2008, 05:24 PM
- By lukky in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-28-2008, 07:33 AM
- By 82rathi.angara in forum Advanced JavaReplies: 3Last Post: 06-13-2008, 02:45 PM
- By dsiwal in forum Threads and SynchronizationReplies: 2Last Post: 06-10-2008, 06:38 AM