0

Hi

I have a program that has a JTree that lists of all the directories on my computer. I also have a JList in and an add button. Now I am trying to select or highlight a directory in the JTree, click the add Button and then update the JList with the name of the node (Directory) I have clicked. I have looked at mouse listeners actionlisteners and tree selectionListeners but cannot come up with anything that seems feasible.


Any suggestions may be helpful

Manythanks

2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by brianlevine
1

Assuming you only allow a single selection in the JTree you can use: JTree.getSelectionPath.

It returns a TreePath which basically holds a list of the hierarchy that is selected. Then you can use TreePath.getLastPathComponent to get the name of the node you're looking for.

HTH

Votes + Comments
Helpful answer.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.