Java Swing JTree update content
I've got the following problem:
I have a Jtree, which is in the left side of my JSplitPane. When I select an item in the tree, I get the option to edit it in the Right part of the SplitPane. Everything works fine so far. Once I editted the item, I pres the save button, which puts my updated item into the database (works fine) and updates the tree to represent the new item. This last part is where the problems begin. The text of the item is not updated. Once I select a different item in the tree the text of the changed Item changes, but I can't figure out how to change it while the text is selected.
Any help would be appreciated.
Try looking at this method.
protected void fireValueChanged(TreeSelectionEvent e)
What's happening is that the tree isn't being redrawn until you've selected a new item.
great, will do.
now to find a way to call it from outside the tree....
I've already tried setting the selection to a different item, calling repaint() and resetting the selection with no effect
What people usually do for things like this is subclass the TreeModel with their own model. Then you expose the model and give it methods like changeData() or something that do exactly what you want them to do and then call the fire... events. You will want to subclass the DefaultTreeModel so that you dont' have to write all of the stuff, but make sure that you override some of the methods if you need to.
Hope this helps.
I was hoping to avoid having to do this. But it looks like I have no choice. Oh well...
Btw. The program I'm currently working on is becoming bigger and bigger, so I could really use some help, if people are interested, send me a PM. The program is (currently) a character generator for the DnD pen and paper Roleplaying Game. But the goal is to make it compatible with all D20 RPGs, and add conline gaming functionality as well.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center