• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree InputMap and Key Bindings  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTree where a context menu is created and for each node I adjust the menu items depending on the type of node. I have Action classes that extend AbstractAction for all of these events.

I need to now duplicate all these actions with keyboard shortcuts. Primarily what I am concerned with at the moment is when I press the Enter key on a leaf node, I need to open a form. I first looked into a KeyListener but this doesn't allow me to reuse the action classes I've already created.

So I started looking at InputMaps and ActionMaps but none of the docs deal with how to utalize these with a JTree. Can anyone point me in the right direction? The trick here is that I want to make sure I don't override default JTree key mapping behavior.

Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> The trick here is that I want to make sure I don't override default JTree key mapping behavior.

would checking the keystrokes do?

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

Not sure I follow what you are trying to tell me. I know I can loop over the existing keys. How does that help me assign mappings to tree nodes?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought you were trying to avoid e.g creating an action for F2, which
would override the current F2 action of the tree, hence the loop to see if
F2 was already mapped.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
I thought you were trying to avoid e.g creating an action for F2, which
would override the current F2 action of the tree, hence the loop to see if
F2 was already mapped.


Ok, I see. So that's fine. I guess more importantly is actually assigned keys to nodes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!