Duplicate tree node on TreeModelSupport.fireChildAdded
To inform my JXTreeTable of a newly inserted node, I use the TreeModelSupport of AbstractTreeTableModel to fireChildAdded.
The problem is: if I do that after resetting the treetablemodel (i.e. JXTreeTable.setTreeTableModel) at some point before, I am getting a duplicate node of the one being added (appearing as a blank row).
Now if you are wondering what resetting the treetablemodel has to do with the way TreeModelSupport.fireChildAdded works, I'll tell you:
fireChildAdded will fire the added TreeModelListeners.
I noticed that the TreeModelListeners that get added to the modelSupport are the following:
When I reset the treetablemodel, due to removing/adding of listeners, they result in the following order:
While debugging, I queried the number of rows in the treetable, and I found that the duplicate row is being inserted after the last listener is fired.
To make sure, I manually reshuffled the listeners and put them back in their original order, and the duplication problem disappeared.
To workaround this issue, I built an internal tree structure in my model, which I populate as the getChild method of TreeModel gets invoked. Before firing a listener, I check: if the node already exists in my structure, this means it was already inserted by some listener, and hence I no longer fire the remaining listeners.
But this workaround prevents me of using TreeModelSupport.fireChildAdded, and forces me to manipulate the listeners myself.
Any idea about this? Your help is greatly appreciated.
Thanks a lot,