Java: Get Selected Node Value Of JTree

To get the selected node value of JTree, you need to add a selection listener in order to be able to detect selections when a node of a JTree has focus (selected) or not. The code below adds a TreeSelectionListener and uses the getLastPathComponent() method of a TreePath object to get the text of the JTree node selected.

Remember that a TreePath contains an array of Objects that refers to the nodes starting from the root until the last one called the leaf.

Related Posts Plugin for WordPress, Blogger...


Leave a Reply

Your email address will not be published. Required fields are marked *