【问题标题】:How to search a node in outline view in swing如何在swing的大纲视图中搜索节点
【发布时间】:2013-05-06 23:47:49
【问题描述】:

我在包含 200 个节点的应用程序中实现了 outline view。如何搜索特定节点并展开它?

我还查看了DefaultMutableTreeNodebreadthFirstEnumeration()depthFirstEnumeration() 方法,但在Outline 中找不到等效方法。

【问题讨论】:

    标签: java swing netbeans outline-view


    【解决方案1】:

    该方法取决于用于构造OutlineModelTreeModel。在引用的FileTreeModel 中,getRoot() 返回一个任意的File,表示分层文件系统中子树的根。可以递归搜索此子树,如here 所示。您无需打印结果,而是将表示路径的 File 实例累积到数组中。该数组将用于构造TreePath。给定这样的treePath,您可以以类似于here 所示的方式显示相应的节点。

    outline.expandPath(treePath);
    outline.scrollRectToVisible(getPathBounds(treePath));
    

    【讨论】:

    • 非常感谢您提供这个想法。虽然我没有使用 FileTreeModel,但我使用的是我自己的自定义模型,并且我会以我的方式实现。再次感谢
    猜你喜欢
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 2017-01-20
    相关资源
    最近更新 更多