렌더링 엔진과 함께 사용할 장면 편집기를 만들려고합니다. 나는 그 스윙을 사용하여 GUI를 만들고 스윙을 사용하여 JXTreeTable
구성 요소를 만듭니다. 장면 트리 테이블이 자동으로 노드 이름을 업데이트하지 않는다는 점을 제외하면 모든 것이 잘 작동합니다. 예를 들어 다음 이미지에서 노드 중 하나의 이름을 변경하면 아무 것도 나타나지 않습니다. 그러나 장면 상자의 노드 (맨 위)에 마우스를 올려 놓으면 이름이 업데이트됩니다.다른 트리 테이블에서 업데이트 된 트리 테이블 값 표시
나는 AbstractTreeTableModel
을 연장 두 JXTreeTable
, 그리고 두 가지 모델이있다. 다음은 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()
을 사용하는 장면 나무 테이블을 업데이트 할 것이라고 생각했다.
fireChildChanged()
을 index = 0으로 호출하면 이름을 바꿀 때 루트 노드를 업데이트 할 수 있지만 업데이트하기 위해 마우스를 움직일 때까지 다른 인덱스를 기다려야합니다.
편집 : 새 텍스트가 더 이상 원본보다이라면 문제는 텍스트 뒤에 "..."내가 부분적으로 일 @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);
당신이 해결책을 발견 다행 - 그냥 조심 :. 그것을가 필요로이 조금 냄새를 수동으로 모델 자체의 _ 외부 _에서 변경 사항을 실행하십시오. sceneModel은 포함 된 객체의 속성에 대한 변경을 감지 할 때 자체적으로 수행해야합니다. – kleopatra
그래, @ Shakedown의 설명을 살펴본 후 잘못된 방식으로이 작업을 수행하고 있음을 알았습니다. 그러나 그것은 여전히 내가 무언가를 달릴 수있게 해 주었고, 이제는 나의 미래의 올바른 구현이 내가 기대하는대로 작동 하는지를 확인할 수있게되었습니다. – NickLH