Setting Focus on a node in JTree

Hi,I would like to know how to set focus on a treenode in JTree so that when it opens one can directly navigate using the up and down arrow key?Priya
[177 byte] By [priyapinto] at [2007-9-26 2:43:25]
# 1

You can do this by using the method fireValueChanged( treeSelectionEvent )

try this out for the root node

TreePath treePath=new TreePath(rootNode);

TreeSelectionEvent event=new TreeSelectionEvent(tree, treePath, false, tree.getLeadSelectionPath(), treePath);

tree.fireValueChanged(event);

i think u know about the key listeners which also be used for ur problem.

Hope this will show u the Path

Shahid

shahid_faiz at 2007-6-29 10:22:04 > top of Java-index,Archived Forums,Swing...
# 2

just implement ur Jtree class with TreeSelectionListener

and add

this.getSelectionModel().setSelectionModeTreeSelectionModel.SINGLE_TREE_SELECTION); or multi selct if required

this.addTreeSelectionListener(this);

and just overide the valuechanged method()

that is it

it will work no firevalue n all

hope it works cos it works for me

cheers

Myquery at 2007-6-29 10:22:04 > top of Java-index,Archived Forums,Swing...