• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter jtree - keeping all nodes and children of nodes that match criteria

 
Ed Kawas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have a JTree of DefaultMutableTreeNodes and I would like to filter them. When I filter them, I want to keep any node that matches my criteria or has children that match my criteria. The filter that I have not seems to only match the root node and children of the root. I am having problems filtering all nodes in the tree.

Any suggestions?

Thanks.
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed,
Welcome to the Ranch.

If you can post your code (just the relevant part, which we can probably run it in our own systems), we can help you figure out whats going wrong.
 
Ed Kawas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, and thanks for the welcome.

So here is my filter class. I have a tree with a text box at the bottom and as you type, the tree is supposed to filter by node name. This is the filtering tree model:



Any ideas?

Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the tree filter here seems to work OK when following your description - textField data/enter
perhaps you can compare and see what's different

http://forums.sun.com/thread.jspa?forumID=57&threadID=5378510
 
Ed Kawas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Their filter is similar to the one that i posted. I got it working, by subclassing defaultMutableTreeNode and extending DefaultTreeModel. I basically keep passing my filter down to all children ...

Thanks for everyone's help.
 
Adam Armistead
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to filter a JTree in the same manner as this post. I currently have a working filter similar to this one or the one int the post referenced by Michael Dunn. My problem is that the filtering is quite slow. If i have 20,000 nodes in my tree with the above code it takes over a minute to filter my tree. I need something that can handle up to say a million nodes or more. I just tested my string comparison filter and I can compare a million nodes in like 2 seconds. So whats the trick to make this filter faster?

Any help would be greatly appreciated.

Adam
 
Ed Kawas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will test out the filter that I have with 20K nodes and see how it performs... I will get back to you!
 
Ed Kawas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that I would post a link to the tree that I ended up using (source is on google code)

http://www.google.com/codesearch/p?hl=en&sa=N&cd=1&ct=rc#OgtcnaRVF5s/taverna/ui/net.sf.taverna.t2.ui-activities/trunk/biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/BiomobyObjectTree.java&q=BiomobyObjectTree%20package:http://taverna\.googlecode\.com

Take a look and see what I did. When I was trying to get this working, I remember that a few iterations of my code resulted in a very slow tree...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic