3

レンダリングエンジンに合わせてシーンエディタを作成しようとしています。私はswingを使用してGUIを作成し、そのJXTreeTableコンポーネントにもswingxを使用しています。シーンツリーテーブルがノードの名前を希望どおりに自動的に更新しないことを除いて、すべてが正常に機能しています。たとえば、次の画像では、ノードの1つの名前を変更しましたが、何も起こらないようです。ただし、[シーン]ボックス(一番上にあるノード)のノードの上にマウスを移動すると、名前が更新されます。

ここに画像の説明を入力してください

私は2つJXTreeTable、そして拡張する2つのモデルを持っていAbstractTreeTableModelます。プロパティモデルに関連するコードは次のとおりです。

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);
    }
}

使うfireChildChanged()とシーンツリーテーブルが思い通りに更新されると思いました。

index = 0で呼び出すfireChildChanged()と、名前を変更したときにルートノードを更新できますが、他のインデックスは、更新するためにマウスをその上に移動するまで待つ必要があります。

編集:問題は解決しました

@Shakedownによって提案された再描画方法を試しましたが、部分的には機能しましたが、新しいテキストが元のテキストよりも長い場合、テキストの後に「...」が残ることがありました。

しかし、問題はTreePathが適切に生成されていないことに起因していることに気づきました。を使用する場合TreePath path = new TreePath(sceneSelection.getParent());、パスの親はnullであったため、ツリーを更新できませんでした。私は今、動作するこのコードを使用しています:

// 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);
4

1 に答える 1

3

SceneModel更新するツリーテーブルではないことをリスナーに通知しています。fireXXXクラスでいくつかの同様のメソッドを探し、AbstractTreeTableModelそれらを呼び出します。これにより、が通知され、JXTreeTableそれ自体が再描画されます。

必要なもののように見えるfireTreeNodesChanged(...)ので、それを試して、渡す必要のあるパラメーターを見つけてください。

于 2011-11-28T03:06:00.050 に答える