Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Maintain focus on JFrame

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Maintain focus on JFrame

    Crossposted: Maintain focus on JFrame - Java Forums

Similar Threads

  1. How can I avoid JTextArea from grabbing focus upon setting text
    By Orit in forum Java Theory & Questions
    Replies: 4
    Last Post: October 4th, 2010, 05:17 AM
  2. [SOLVED] JTextPane focus problem
    By LeonLanford in forum AWT / Java Swing
    Replies: 3
    Last Post: June 21st, 2010, 11:50 PM
  3. switch focus to another window
    By tuansoibk in forum AWT / Java Swing
    Replies: 1
    Last Post: November 13th, 2009, 02:02 PM
  4. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 01:37 PM
  5. Replies: 9
    Last Post: June 27th, 2009, 04:05 PM