javaswingjtreedefaulttreemodel

static filtering of a JTree/ multiple Jtrees sharing (the relevant parts of) a model


I have a Jtree With two top children Say A and B. Currently the code is designed to show both in the same panel as they are part of a shared JTree. What I want to do is, seperate A and Binto two different panels.

Now, the Jtree has a complicated update system and there are ways of A members automatically entering B, vice versa, etc. and I don't really want to have two seperate JTrees. I know I can access the relevant data using:

myTree.getModel().getChild(myTree.getModel().getRoot(),i)

but is there a way of displaying A and its sub-children in one panel and B in another?

if no, I guess I will have to resort to creating myTree_A and myTree_B which will track myTree. What is the neatest and msot efficient way of doing this?

Update:

So I opted for creating two separate trees. I however have a small problem, when I 'root_A.add(A)' and 'root_B.add(B)' in my two new trees, where root_A and root_B are myTreeA and myTreeB's roots respectively, A and B are detached from myTree's root and I can no longer hook the elements of myTreeA,B to the original myTree and call the relevant routines. Any way of telling myTreeA and myTreeB to track A and B without deleting their parent? In other words, can I share models/nodes between trees?


Solution

  • The neatest way will be to create two separate trees so that models attach to A and B can be easily updated and reflected easily.