qq_35918413
qq_35918413
2019-05-04 11:33

JAVA编写GUI界面时如何用一个新的JTree对象将之前的JTree对象覆盖掉?

  • java
  • eclipse

tree是一个成员变量,我先写了个方法生成了一个空的树,然后想在更新树的方法里给tree重新赋值来覆盖掉原先的空树,可是运行时覆盖不掉,那个树还是显示为空。就想问一下如何才能覆盖之前的树以达到更新树的目的?

//生成树
public void layoutTreePanel() {
DefaultMutableTreeNode initTree = new DefaultMutableTreeNode(null);
tree = new JTree(TreePath);
setTree(path,TreePath);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(tree);
treePanel.add(scrollPane,BorderLayout.CENTER);

}

//更新树
public void showTree(String str) {
    String path = str;
    DefaultMutableTreeNode TreePath = new DefaultMutableTreeNode(path);
    tree = new JTree(TreePath);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(tree);
    treePanel.add(scrollPane,BorderLayout.CENTER);

}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换