aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes filter jtree - keeping all nodes and children of nodes that match criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "filter jtree - keeping all nodes and children of nodes that match criteria" Watch "filter jtree - keeping all nodes and children of nodes that match criteria" New topic
Author

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

Ed Kawas
Greenhorn

Joined: Jun 03, 2009
Posts: 5
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.

http://ekawas.blogspot.com
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10532
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ed Kawas
Greenhorn

Joined: Jun 03, 2009
Posts: 5
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Jun 03, 2009
Posts: 5
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

Joined: Jul 28, 2009
Posts: 1
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

Joined: Jun 03, 2009
Posts: 5
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

Joined: Jun 03, 2009
Posts: 5
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter jtree - keeping all nodes and children of nodes that match criteria