显示另一个树表中更新的树表值
我正在尝试制作一个场景编辑器来配合我的渲染引擎。我使用 swing 来制作 GUI,并使用 swingx 来制作其 JXTreeTable
组件。一切工作正常,除了场景树表没有按照我的意愿自动更新节点的名称。例如,在下一个图像中,我更改了其中一个节点的名称,但似乎没有发生任何事情。但是,如果我随后将鼠标移到“场景”框中的节点(顶部的节点)上,名称就会更新。
我有两个 JXTreeTable
和两个扩展 AbstractTreeTableModel< 的模型/代码>。 这是 Properties 模型的相关代码。
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);
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.
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在通知
SceneModel
的侦听器,它不是您要更新的树表。在AbstractTreeTableModel
类上查找一些类似的fireXXX
方法并调用这些方法,这将通知JXTreeTable
并且它会重新绘制自身。看起来您想要的是
fireTreeNodesChanged(...)
,因此请尝试一下并找出需要传入哪些参数。You're notifying the listeners of the
SceneModel
which is not the tree-table that you want to update. Look for some similarfireXXX
methods on theAbstractTreeTableModel
class and call those, which will notify theJXTreeTable
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.