首页 > 解决方案 > Replacing a file tree component in Java Swing to another

问题描述

I need help using java swing to replace the dummy file tree on the left side of the GUI in SB_Administrator.java to the the more advanced java tree of FileTree.java.

I am currently using windowBuilder in Eclipse.

Thanks in advance for your help

SB_Administrator.java


        // Get the root node of the tree
        DefaultMutableTreeNode rootSess = (DefaultMutableTreeNode) tree.getModel().getRoot();
        //rootSess.setUserObject(sess);     // remember the Session in it


        splitPane.setLeftComponent(tree);

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        splitPane.setRightComponent(tabbedPane);
    }

}

FileTree.java

............................................................................................................................................................................................................................................................................................................................

标签: javaswingdata-structuresfilesystemsjtree

解决方案


  1. 创建一个新FileTree对象
  2. 将对象作为参数File(eq new File("root_path"))
  3. splitPane.setLeftComponent(tree)用新树替换旧树splitPane.setLeftComponent(fileTree)
FileTree fileTree = new FileTree(new File("./"));
splitPane.setLeftComponent(fileTree);

推荐阅读