Perry Smith

Java Questions & Answers

Archive

Home / Java Q & A Archive Page 1 / Java Q & A Archive / Java Q & A Main Page


(from-name) Pekka Hippeläinen
(from-email) phippela@cc.hut.fi
( Java.)

Hello,

I have constructed a normal tree and inserted some nodes into it. I have some problems with the handles that appear on the left side of the tree item

When you create a new node (parent), the handle appears to be not expanded. At this point the node doesnt have any children. All is ok, if you enter some children to this parent and then expand the node. But if you expand a node without any children I lose the handle and user cannnot see any new nodes created. (The new nodes are really there, but the parent wont expand unless, I perform some operation, such as own made copy). I also lose the handle if I remove all the children from a node or user double clicks the node without any children. (The parent node´s isLeaf() returns false, even when all the children are removed.)

The handles seems to be not so well documented in the net and any help will be greatly appreciated!

Thanks,

Pekka Hippelainen (phippela@cc.hut.fi)

ps. I also doesnt seem to have those nice dotted lines, which clarify the tree structure, and only filled circles instead of the folders (this could be problem with the look&feel).


Response

(from-name) Pekka Hippeläinen
(from-email) phippela@cc.hut.fi
( Java.)

!!Many thanks to Elias Martenson!!!

You have to pass a TreeModelEvent to the TreeEventListener

If you are using DefaultTreeModel you should call for example: ownDeafaultTreeModel.nodeStructureChanged(parentOfTheChangedTreeNode)

after you have done some editing to the tree structure.

The answer to the ps. was as follows: When you have created the tree you should call

tree.putClientProperty( "JTree.lineStyle", "Angled" )


Home / Java Q & A Archive Page 1 / Java Q & A Archive / Java Q & A Main Page