Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

navigate a JTree with JButton(s)

 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JTree representing a simple hierarchy. I also have four buttons to navigate through the tree (first , previous, next,last JButton(s))

I want to implement the following functionality :

if i click a given button the current selected node in JTree should be set accordinely to chosen button : ex if i click next button ; then JTree should select the node directly under current selected node ..and so for each button.

can some one suggest some code to do that ?

thanking you.
 
Alice Corman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a thought, but if your tree nodes extend DefaultMutableTreeNode you might be able to use the built in methods like getPreviousNode(), getNextNode(), to obtain the previous/next node in preorder traversal. Once you have the correct node, just make sure the node is visible/expanded in the JTree.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic