Question

I am trying to make a scene editor to go with my rendering engine. I am using swing to make the GUI and also swingx for its JXTreeTable component. Everything is working fine, except that the Scene tree table is not updating the names of the nodes automatically as I would like. For example, in the next image, I change the name of one of the nodes, and nothing seems to happen. However if I then move my mouse over the node in the Scene box (the one at the top) the name gets updated.

enter image description here

I have two JXTreeTable, and two models which extend AbstractTreeTableModel. Here is the relevant code for the Properties model.

public class PropertiesModel extends AbstractTreeTableModel{
    private EE_Property root;
    private SceneModel mSceneModel;
    private EE_SceneObject sceneSelection;

    ...

    @Override
    public void setValueAt(Object value, Object node, int column){
        ((EE_Property)node).setValue((String)value);

        // Updates the values of the current scene selection
        sceneSelection.setProperties(root);

        TreePath path = new TreePath(sceneSelection.getParent());
        int index = mSceneModel.getIndexOfChild(sceneSelection.getParent(), sceneSelection);

        // This is where I thought the updating of the scene model would happen and thus redraw it correctly
        mSceneModel.getTreeModelSupport().fireChildChanged(path, index, sceneSelection);
    }
}

I thought that using fireChildChanged() would update the scene tree table as I wanted.

If I call fireChildChanged() with index=0, I can get the Root node to update when I rename it, but any other index I have to wait till I move the mouse over it to update.

Edit: problem solved

I tried the redraw method suggested by @Shakedown which partially worked but sometimes would leave "..." after the text if the new text was longer than the original.

I did however realize that the problem was coming from the TreePath not being generated properly. When using TreePath path = new TreePath(sceneSelection.getParent());, the path's parent was null, thus not allowing the tree to update. I now use this code which works :

// mTT is the scene tree table
TreePath nodePath = mSceneModel.mTT.getTreeSelectionModel().getSelectionPath(); 
int index = mSceneModel.getIndexOfChild(sceneSelection.getParent(), sceneSelection);
mSceneModel.getTreeModelSupport().fireChildChanged(nodePath.getParentPath(), index, sceneSelection);
Was it helpful?

Solution

You're notifying the listeners of the SceneModel which is not the tree-table that you want to update. Look for some similar fireXXX methods on the AbstractTreeTableModel class and call those, which will notify the JXTreeTable and it will redraw itself.

It looks like the one you want is fireTreeNodesChanged(...), so play around with that and figure out what parameters you need to pass in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top