aspose file tools
The moose likes Swing / AWT / SWT and the fly likes How do I know which object is selected? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How do I know which object is selected?" Watch "How do I know which object is selected?" New topic
Author

How do I know which object is selected?

Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
Hi,
I have a JTree which is made up of nodes (Tests) and leaves(test steps) when the user clicks on the tree I need to know which item has been selected. However my problem is I am having to cast the selected node to enable me to use it, but obviously need to cast it inot the correct object. I have tried to create a superclass which both the test and the testsep class extend but am still stuck on how I can test to see which type the returned object really is.
Thanks
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
You can use either of these expressions:
selectedNode.isLeaf()
selectedNode.getUserObject() instanceof TestCase
You do need to find this out before cast to TestCase.
[ April 07, 2004: Message edited by: Steve Lovelace ]

The Inner that is named is not the true Inner.
Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
Thanks Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I know which object is selected?
 
Similar Threads
Labeling JTree nodes
How to check given field whether primitive or user defined
Drawing at nodes
getNextLeaf()
JTree not updating