JTree [+] and [-] icon

In JTree i want every nodes to diplay [+] or [-] icon next to it. can anyone help me on this.Thanks in advance....
[128 byte] By [Sarjaya] at [2007-10-2 19:37:13]
# 1
+ will be displayed only when a child node exists for the node and this node is collapsed and - is displayed when the node is expanded. Have you tried something?
ajitrma at 2007-7-13 21:25:42 > top of Java-index,Desktop,Core GUI APIs...
# 2

In the past I had a problem where we were dynamicaly updating the nodes on a tree, i.e child nodes would not get populated until the user expanded the tree. For example when the user expanded a node a database query would be run and the results inserted into the tree.

In order to get the + - next to the tree nodes when there was no real child nodes I put a dummy object under each node of the tree (e.g. just a new java.lang.Object()). When the user expanded the tree node the database query was run, if there was any data the tree was updated with the data from the database and the dummy object removed, if there was no data to display you just remove the dummy object from the tree.

By adding the dummy object you essentialy trick Swing into displaying the + - next to the tree nodes, this in turn alows you get receive tree exapnded and collapsed events.

Hope this helps

jspflya at 2007-7-13 21:25:42 > top of Java-index,Desktop,Core GUI APIs...