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 / GUI / February 2005

Tip: Looking for answers? Try searching our database.

help w/ WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

Thread view: 
wizumwalt - 15 Feb 2005 01:39 GMT
I have a 3D canvas inside a JPanel which is inside one of my tabs of a
JTabbedPane. My problem is that when I press the 'CTRL' + 'UP' arrow
when the focus is on the canvas, the focus then moves from the canvas to
the tab of my JTabbedPane and I don't want this.

I was told I should remove the Ctrl-Up key binding from the
JTabbedPane's InputMap using WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.  But
I'm not sure how do to this, nor which component this should be done to.

I currently have this ...

public class MyClass extends JFrame implements ActionListener, ItemListener,
        ChangeListener
{
   ...
   public void actionPerformed(ActionEvent ae) {
      // lots of menu commands
   }
...
}

Any help much appreciated.

Will
John McGrath - 15 Feb 2005 19:10 GMT
> I was told ...

Note:  It is generally better to reply to the message, rather than start a
new thread.  That makes it easier for people to follow the conversation.
I would have also seen this message and replied earlier, since my
newsreader will highlight replies to my messages.

> I should remove the Ctrl-Up key binding from the JTabbedPane's InputMap
> using WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.  But I'm not sure how do to
> this, nor which component this should be done to.

I first suggested removing the key binding, but now that I think about it,
you probably do not want to do that.  All InputMaps have a (possibly null)
parent InputMap.  The look-and-feel sets up an InputMap for each component
class and then each component instance gets an InputMap which has the
class InputMap as a parent.

You could remove the binding from the class InputMap, but that would
affect every JTabbedPane in the JVM, so that is not a good idea.  And you
cannot remove the binding from your tabbed pane's InputMap, since it is
not there in the first place.  But you can add a new binding to the
component's map, which will supersede the definition in the parent map.

An InputMap maps a KeyStroke to an "actionMapKey", which is then used to
look up the action for the keystroke in the ActionMap.  So all you need to
do in order to "unbind" the KeyStroke is to map it to an actionMapKey that
does not exist, such as "DoNothing":

  InputMap map = tabbedPane.getInputMap(
     JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
  KeyStroke keyStroke = KeyStroke.getKeyStroke(
     KeyEvent.VK_UP, InputEvent.CTRL_MASK, false );
  map.put( keyStroke, "DoNothing" );

Signature

Regards,

John McGrath

wizumwalt - 16 Feb 2005 02:14 GMT
>>I was told ...
>
> Note:  It is generally better to reply to the message, rather than start a
> new thread.  That makes it easier for people to follow the conversation.
> I would have also seen this message and replied earlier, since my
> newsreader will highlight replies to my messages.

Apologies, and thank you very much for this help. That did it.

>>I should remove the Ctrl-Up key binding from the JTabbedPane's InputMap
>>using WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.  But I'm not sure how do to
[quoted text clipped - 22 lines]
>       KeyEvent.VK_UP, InputEvent.CTRL_MASK, false );
>    map.put( keyStroke, "DoNothing" );


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.