This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Mapping Keys to nodes in JTree

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am developing a Chat application. In this the users are shown in a tree.How do i map keys to these nodes such that when i press a key, focus goes to the node that begins with that letter.
For instance, if i press 'J', focus should go to the node which starts with 'J'( Joseph for instance). If there are more than one node starting with 'J', let focus go to the first such node.
Please help me out. Code examples will be very helpful
...thanks
...Saj
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you should implement a KeyListener for your tree. In this listener, when a key is pressed you must find the node that begins with that letter and get a TreePath accord with the node. Then you set selected node by the TreePath. However, it isn't possible work if you use addKeyListener(KeyListener) method to add listener for the tree. The JTree has a class (BasicTreeUI) that is used to render and handle events for the tree. In this class has an inner class that implements KeyListener and you can create your class that is extended from BasicTreeUI. In your class, you should modify the inner class to handle things.

Originally posted by Sajee Joseph:
Hi,
I am developing a Chat application. In this the users are shown in a tree.How do i map keys to these nodes such that when i press a key, focus goes to the node that begins with that letter.
For instance, if i press 'J', focus should go to the node which starts with 'J'( Joseph for instance). If there are more than one node starting with 'J', let focus go to the first such node.
Please help me out. Code examples will be very helpful
...thanks
...Saj


 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you should implement a KeyListener for your tree. In this listener, when a key is pressed you must find the node that begins with that letter and get a TreePath accord with the node. Then you set selected node by the TreePath. However, it isn't possible work if you use addKeyListener(KeyListener) method to add listener for the tree. The JTree has a class (BasicTreeUI) that is used to render and handle events for the tree. In this class has an inner class that implements KeyListener and you can create your class that is extended from BasicTreeUI. In your class, you should modify the inner class to handle things.
Please refer to BasicTreeUI class.
 
this is supposed to be a surprise, but it smells like a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic