0

I'm creating an app with JTabbedpane and I made a function that adds tabs with a click of a button. The tabs contain JTrees. After I add tabs I want to be able to add nodes to the trees in the tabs.

Now, because tabs and trees are created programmatically, how can I access a specific JTree in a specific tab so I can add nodes to it?

Thanks in advance.

Igor
  • 1,532
  • 4
  • 23
  • 44

1 Answers1

1

You should have class that extends tab instead of working directly with the concrete Tab, and have methods that add/get a tree from it. So you create an instance of tab, you create the tree, then you add it to the tab. If you don't know how many tabs that will be created, keep them in a list.

Momo
  • 2,471
  • 5
  • 31
  • 52
  • and if I decide to add a new node to a tree like this: trees[i].add(node); ... would it refresh that specific tree in the tab? – Igor Sep 02 '12 at 18:09
  • ...or do I have to recreate all tabs when tree content changes? – Igor Sep 02 '12 at 18:23
  • You should work with a Model instead of the Tree. A good reference here http://stackoverflow.com/questions/1913855/how-can-i-refresh-a-jtree-after-adding-some-nodes-to-the-underlying-model – Momo Sep 02 '12 at 18:44