3

I have a class TreeNode which has some attribitues and a ArrayList of children.

For this class I have my own TreeModel which extends AbstractTreeTableModel. The created tree is displayed correctly.

Now I want to add a search field which searches in one attribute and show all parents and all children when it matches with one node. So I have to traverse the tree up and down.

I tried to use a SerachFactory but it only searches visible nodes.

An Example would help me a lot or best practise. Do I need a second Model (which extends AbstractTreeTableModel) where a filter can be applied? How can I do that? Or is the way to go over a Renderer?

joragupra
  • 692
  • 1
  • 12
  • 23
janor
  • 179
  • 1
  • 10
  • unfortunately, that's a non-trivial endevour - there are several options, none really satisfactory. Search for QAs for filtering a plain TreeModel on this site (sorry, don't have a link handy) to get you going (a TreeTableModel is-a TreeModel) – kleopatra Apr 16 '14 at 09:04
  • found one reference: http://stackoverflow.com/questions/9234297/filtering-on-a-jtree – kleopatra Apr 16 '14 at 09:17
  • Thank you. I tried to implement a filtered model, but i have a problem to update the view. How can I do this? I tried tree.setTreeTableModel(filteredModel); TreeModelSupport tms = new TreeModelSupport(filteredModel); tms.fireNewRoot(); In the DefaultTreeModel, which I can't use, there is a reload method - like in http://www.adrianwalker.org/2012/04/filtered-jtree.html – janor Apr 16 '14 at 12:26
  • you can implement the reload just the same way as DefaultTreeModel does it, just look at its source code :-) – kleopatra Apr 16 '14 at 13:13
  • Ok I can try to implement these methods. But they are 5 complex methods with an other underlying data structure (Arrays). Is there no easy way to update the model? – janor Apr 16 '14 at 13:41
  • protected void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children) This method I think I must call but in my derived model the method ist not available? It extends AbstracTreeTableModel – janor Apr 17 '14 at 07:16

0 Answers0