开发者

Shift focus from one JTree node to another

I need to shift focus from a JTree node to another node on the previous node being clicked.

Example XML document:

<br/>
<'obo'><br/>
<'term'><br/>
<'id'>GO:0001<'/id'><br/>
<'name'>candida... '<'/name'><br/>
<'dbname'>' blah blah '<'/dbname'><br/>
<'is_a'>'GO:0035'<'/is_a'><br/>
<'/term'><br/>
<'term'><br/>
<'id'>'GO:0035'<'/id'><br/>
<'name'>'candida... '<'/name'><br/>
<'dbname'>' blah blah '<'/dbname'><br/>
<'开发者_开发问答is_a'>'GO:00465'<'/is_a'><br/>
<'/term'><br/>
<'/obo'><br/>

I have made this into a JTree. Now I need to shift focus to GO:0035 when the user clicks on GO:0001.

I was trying to addTreeSelectionListener() but it doesn't not work in my Eclipse. I thought I could set a loop read each check if there is a corresponding , if there is a corresponding then get it's path, add a mouseListener to G0:0001 and setPath to GO:0035. I'm new to Java so I'm not particularly sure how to do this. Please help out!! :(


It's not clear how you are constructing your JTree or TreeModel, but you can find examples in How to Use Trees. If you use the DefaultTreeModel, you can search from the node returned by the model's getRoot() method, and you can construct a TreePath to that destination node. Use the tree's setSelectionPath() method to select the node found.

If you still have trouble, edit your question to provide an sscce that shows your usage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜