hi. i have a filteredtreemodel that extends DefaultTreeModel
what i want to do is at the end of each parent node, i place a Jbutton as a leaf node that says show/hide.
when this button is clicked, it will only show like the 1st 5 leaf nodes if button labeled, hide. if it is labeled show, it will display all leaf nodes
my problem is that whenever i iterate from the parentnode using either getChildAt() or children() from the DefaultMutableTreeNode and i loop the nodes one by one, it doesn not seem to be in order
if it was displayed in order, this would be easy. however it is not and i cant understand why it's outputted in random and not in sequence as when you added them to the treemodel.
Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.
So it puts the new nodes into the end of the list.
The getChildAt says:
Returns the child at the specified index in this node's child array.
I'm sure this class behaving according to it's documentation, so it will give back the nodes in the right order.
posted 10 years ago
this is my working code
im not sure if my filter tree model is the problem because when i run my app, it works fine either in show all or hide mode. the problem occurs when i click the button to either show or hide, it gives me an array index out of bounds exception. and i am not sure where in my filtertree class the problem lies. please advise. thank you
by the way, my jtree has checkbox leaf nodes in it, and the last leaf node for every parent node is a jbutton where the show/hide functionality happens. coz my leaf nodes may be lots of them so i want to be able to hide so only the 1st 5 leaf nodes of every parent node appears.
They do return in the sequence they were added. Please try it without your FilteredTree code and you will see that it works fine. I'm almost sure that your code makes it invalid, but I won't spend my time debugging your code, till you won't post a runnable example.
posted 10 years ago
hi miklos. yes. i will post it. hopefully tomorrow night gmt+8. i did not bring my source with me right now. there are actually 6 files in total because my tree nodes are either jcheckbox and a jbutton as the last leaf node.
is it ok to post them all here? i might just rar them and host it some place else
what i want with my tree is that if i click the show button, it will change its status to HIDE, and will show all leaf nodes
in the CheckBoxNode class, i re-used the variable selected for the button so i could use it to base my show/hide state. but in the QueueCheckBoxNodeEditor where the button click action takes place, i dont think the "editor" object can be converted to class CheckBoxNode so im stuck with how to make this work.
and in the QueueTreeFilter class, if you system.out the nextNode object, it is not outputted in order. my logic was if it encounters a button, it will remove all leaf nodes before it except the 1st three.
hey thanks. i am using the 2nd link classes now. and i extended my CheckBoxNode class to inherit InvisibleNode
and in my main class, instead of the queuetreefilter i used the invisiblemodeltree. same sequence of code. but when i reload the tree model after setting the node invis and/or unsetting, the nodes are still there. they dont disappear.
i debugged the code, the visible attribute it set to invis when i i set it. the problem is when the filter is activated, it does not hide it
hi. i actually made this work now using the invisibleNode link you gave to me. i jut got one tiny little problem,
you see, if Location is the root node, it works with no problems
after I added two sets Location and Location 2 under root, the error pops up. java.lang.NullPointerException. and the stacktrace doesnt give me the line number where the error may be but it's within the java class