Results 1 to 3 of 3
  1. #1
    nik_meback is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default 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?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Don't use a key listener if possible but instead use key binding. The Swing tutorials will show you how these work.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

Similar Threads

  1. How to maintain scrollbar position on postback?
    By marathaWarrior in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-02-2009, 08:35 AM
  2. can we maintain single session from applet?
    By kuppi in forum Java Applets
    Replies: 7
    Last Post: 11-04-2008, 06:24 PM
  3. how to maintain cookies throughout the website
    By lukky in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-28-2008, 08:33 AM
  4. Lack of memory maintain to Website
    By 82rathi.angara in forum Advanced Java
    Replies: 3
    Last Post: 06-13-2008, 03:45 PM
  5. Maintain same session in two application running on same server
    By dsiwal in forum Threads and Synchronization
    Replies: 2
    Last Post: 06-10-2008, 07:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •