java - 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
............................................................................................................................................................................................................................................................................................................................
解决方案
- 创建一个新
FileTree
对象 - 将对象作为参数
File
(eqnew File("root_path")
) splitPane.setLeftComponent(tree)
用新树替换旧树splitPane.setLeftComponent(fileTree)
FileTree fileTree = new FileTree(new File("./"));
splitPane.setLeftComponent(fileTree);
推荐阅读
- python - Django - 将查询集转换为 html 元素
- javascript - Chrome 扩展 - 将变量从 HTML 文件传递到 .js 文件
- mysql - 如何从 PHP 中的两个查询(数组)生成一个可以进一步处理的 $table?
- python - 大写()文件中for循环中的第一个字符
- c - 使用指针的辅助函数
- android - 带有支持库 (14+) 的片段转换 API 不执行任何转换
- javascript - 递增一个 int,但同时有多个用户
- python - 无法使用 Anaconda3 Distrobution 导入 Numpy
- python - 无法在我的 PyQT5 应用程序中使用 joblib 并行运行方法,
- asp.net - 为什么向 asp.net core 发送 POST 请求失败?