JTree add nodes on startup of application

╄→尐↘猪︶ㄣ 提交于 2019-11-27 09:46:35
trashgod

I use this FileTreeModel for the TreeModel, Outline for the view, and user.dir for the starting directory.

TreeModel treeModel = new FileTreeModel(
    new File(System.getProperty("user.dir")));
OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(
    treeModel, new FileRowModel(), true, "User Directory");

Make a recursive function that takes in the root node, adds nodes for each file/dir underneath it, and then calls itself again on each of those nodes.

Edit: no need to inherit from DefaultMutableTreeNode if each node already contains the relative path.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!