Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Prioritising keyboard focus

Thread view: 
Simon Andrews - 21 Jun 2007 15:02 GMT
I have a swing application which contains several panels.  I want one of
the panels to respond to the arrow keys and have registered accelerators
in a JMenu which do this correctly.

However, one of the other panels contains a JTree, and when this is
selected with the mouse it grabs the arrow key events first and they
don't make it back to the menu.

I've tried removing the binding in the tree by doing

tree.getInputMap().put(arrowKeyStroke,"none")

..for each arrow key.  This stops the tree from responding to the key,
but it doesn't allow the event to pass back to the menu.

I've also tried using:

tree.unregisterKeyboardAction(arrowKeyStroke)
and
tree.getInputMap.remove(arrowKeyStroke)

..which didn't seem to have any effect at all.

How can I stop the JTree from capturing these events at all?

Cheers

Simon.
Simon Andrews - 22 Jun 2007 16:03 GMT
> I have a swing application which contains several panels.  I want one of
> the panels to respond to the arrow keys and have registered accelerators
[quoted text clipped - 3 lines]
> selected with the mouse it grabs the arrow key events first and they
> don't make it back to the menu.

Replying to myself in case anyone else can benefit from this.

I've got around this in the end by making a subclass of JTree which
immediately gives away keyboard focus as soon as it gets it.

private class UnfocusableTree extends JTree implements FocusListener {
       
  public UnfocusableTree (TreeModel m) {
    super(m);
    addFocusListener(this);
  }

  public void focusGained(FocusEvent e) {
    application.requestFocus();
  }

  public void focusLost(FocusEvent e) {}

}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.