Update one Jtree's model on the basis of another Jtree's selection

50 views Asked by At

I have a JTree using a DefaultTreeModel and DefaultMutableTreeNodes which contain a business object instance.

When I select a leaf node, I know the business object instance is one of two classes that share the same parent class.

I have a second JTree also using a DefaultTreeModel and DefaultMutableTreeNodes which represent certain types of data that appear in the business object instances.

I wish to update the second JTree's model so that I can select/drag/drop a particular leaf node and then display that data elsewhere.

I have been trying to figure out how to do this reading the various tutorials and other web resources that I think are relevant, however I am having trouble understanding how I can do this "correctly".

The closest I can get at the moment is to respond to the selection event in the first JTree by subscribing the second JTree to selection events, pulling the business object instance out of the selected node and doing a is instanceOf operation to decide what to do next. This of course feels horribly wrong.

How can I best achieve updating the second JTree's view depending upon which class instance is selected in the first JTree's view?

0

There are 0 answers