java - 将 Java Swing 中的文件树组件替换为另一个文件树组件

标签 java swing data-structures filesystems jtree

我需要使用 java swing 将 SB_Administrator.java 中 GUI 左侧的虚拟文件树替换为更高级的 FileTree.java 的 java 树。

我目前正在 Eclipse 中使用 windowBuilder。

预先感谢您的帮助

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);
    }

}

文件树.java

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

最佳答案

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

关于java - 将 Java Swing 中的文件树组件替换为另一个文件树组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59887220/

相关文章:

java - 让 XmlPullParser 忽略空格?

java - 将 Arraylist 导入到 JTable

java - 当一个长进程正在运行时,如何在我的 JFrame 中加载动画 GIF?

algorithm - 如果堆栈操作的时间复杂度为常数 O(1),则该算法的时间复杂度是多少?

java - 按排序顺序获取树的所有叶子

java - 如何在工作区级别的 vscode 中设置 java vmargs

java - 运行 Junit 测试用例时未设置 Spring 4 application.properties @Value

java.lang.NoClassDefFoundError : android. 媒体.ThumbnailUtils

java - 在 Java 中最大化 JFrame

java - java中感知器实现的数据结构困惑