Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swing keyboard focus



Thanks. I've already started doing that and calling setFocusable(false) on all my buttons does solve most of the problems. Changing the input map of the tabbed pane to override the left and right arrow behaviour fixes the other problems.

Basically, I'm implementing a QuickTime movie controller with extra control buttons. I want the keyboard shortcuts to be consistent irrespective of which button has focus (in fact, it makes no sense for buttons to have focus). When the movie panel has focus shortcuts like left or right arrow, space, and other keys have specific meanings and Swing only gets in the way - the less default handling of events the Swing components I'm using do the better!

As I said, part of the problem is that the code predates Java 1.4 and the setFocusable method, so is already embued with various tacky kludges. I think I'm getting close to a neater and more robust long term solution though!

-Rolf

At 12:04 pm -0800 3/1/06, Anton Kast <email@hidden> wrote:

I see two ways to go if you want to dispatch all key events in one place: you can either dominate the keyboard focus management, so only your top-level container ever gets the focus; or you can bypass the regular AWT keyboard event dispatch hierarchy and just filter Toolkit events in a global listener.

To dominate keyboard focus management, you can do things like setting a
custom focus traversal policy on your tabbed pane (no focus cycle down) and
setFocusable(false) on all those troublesome buttons (for instance, through a
button factory).  For keyboard focus on or after Java 1.4, I like the
tutorial at http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html.
...
There is of course a third way to go: reconsider your assumption that
keystroke event logic shouldn't be associated with GUI components.  I have
trouble imagining why you're taking this course, unless it's just to prevent
keystrokes from activating buttons.  Maybe all you want is to prevent your
buttons from gaining focus.

Anton Kast

-- Rolf Howarth Square Box Systems Ltd Stratford-upon-Avon UK. http://www.squarebox.co.uk _______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.