문제

이는 새로운 노드가 추가 될 때마다라고 불리는 것의 방법입니다. MARESTIMEDELLISTMODEL은 .clear () 메소드가 필요합니다. DefaultTreemodel은 not.help가 필요합니다.

    public void fillUserList(){

    List<User> userFriends = ClientController.getInstance().getPrieteniiUserului(user);

    for(int i=0;i<userFriends.size();i++){
        User user = userFriends.get(i);

        model.insertNodeInto(new DefaultMutableTreeNode(user.getNume()), root, i);

    }

    System.out.println(userFriends);

}
.

도움이 되었습니까?

해결책

나는 그것을 해결했다. 새로운 코드는 이렇게 보입니다.

public void fillUserList(){    
    List<User> userFriends = ClientController.getInstance().getPrieteniiUserului(user);
    root.removeAllChildren(); //this removes all nodes
    model.reload(); //this notifies the listeners and changes the GUI
    for(int i=0;i<userFriends.size();i++){
        User user = userFriends.get(i);
        model.insertNodeInto(new DefaultMutableTreeNode(user.getNume()), root, i);        
    }
}
.

다른 팁

삭제 root 노드를 포함하여 모든 노드 을 실제로 필요로하는 경우 모델을 null로 만들어야합니다.다음과 같이 :

mytree.setModel(null)
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top