Java How To Check If Node In Tree Is Selected?

Go To StackoverFlow.com

2

i have a JTree in Java with different parent nodes such as computers, gaming systems, tv's, and networking equipment, with my root node being "technology" what i wanted to do was, whenever a user clicks on one of the nodes (for example under the gaming systems node i have xbox360 and ps3) so if the user where to click on ps3, a web browser would pop up, taking them to the ps3 main website. I know how to do that with the Desktop class in java, but i am unsure as to how i can check if the node has been selected, or if a mouse click has been released, since nodes do not offer MouseListeners or such. Any help? Thanks!

2012-04-05 01:26
by Alejandro


2

The JTree responds to the TreeSelectionListener rather than the MouseListener. Try this page for some examples.

2012-04-05 01:36
by Vincent Ramdhanie
Thanks so much! I got it to work now, thank you - Alejandro 2012-04-07 23:56
Ads