访问 netbeans 大纲中的树对象

发布于 2024-09-01 20:24:26 字数 82 浏览 8 评论 0原文

我正在使用 netbeans 中的 Outline 来显示一些结构化数据。

如何将选定的行映射到树中的对象?

I'm using Outline from netbeans to display some structured data.

How can I map selected row to an object in tree?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2024-09-08 20:24:26

您可以查看今天宣布新的 Swing 树表< /a>.看起来作者正在创建数据模型,因此< em>响应节点选择应该会有所帮助。我在 NetBeans 6.8 中找到了 org.netbeans.swing.outline.Outline 类:

NetBeans/platform11/modules/org-netbeans-swing-outline.jar

附录:

请注意,Outline 源自 JTable,因此 如何使用表格:用户选​​择 可能会有所帮助。根据上面引用的示例,这里有一个侦听器,它显示当节点展开和折叠时行号的明显变化,并且选择保持不变

outline.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
        int row = outline.getSelectedRow();
        File f = (File) outline.getValueAt(row, 0);
        if (!e.getValueIsAdjusting()) {
            System.out.println(row + ": " + f);
        }
    }
});

: .html" rel="nofollow noreferrer">临时,您可以查看 OutlineModelDefaultOutlineModel。前者实现了 TreeModelTableModel 并提供 TreePathSupport;后者提到“TableModelEvent 和 TreeModelEvent 之间的阻抗不匹配”。

与 JTable 一样,视图中选定的行索引可能与模型中的相应行不匹配,这可能是由于排序等原因。 getValueAt() 方法似乎是一种便捷的方法调用convertRowIndexToModel()。这在 Swing 的可分离模型架构中很常见,该架构“将每个组件的视图和控制器部分折叠成单个 UI(用户界面)对象”。请参阅Swing 架构概述

You might look at the example in Announcing the new Swing Tree Table today. It looks like the author is Creating a Data Model, so Responding to Node Selection should be helpful. I find the class org.netbeans.swing.outline.Outline in NetBeans 6.8:

NetBeans/platform11/modules/org-netbeans-swing-outline.jar

Addenda:

Note that Outline descends from JTable, so How to Use Tables: User Selections may be helpful. Based on the example cited above, here's a listener that shows the apparent change in row number as nodes expand and collapse and the selection remains constant:

outline.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
        int row = outline.getSelectedRow();
        File f = (File) outline.getValueAt(row, 0);
        if (!e.getValueIsAdjusting()) {
            System.out.println(row + ": " + f);
        }
    }
});

Although provisional, you might look at OutlineModel and DefaultOutlineModel. The former implements both TreeModel and TableModel and offers TreePathSupport; the latter mentions the "impedance mismatch between TableModelEvent and TreeModelEvent."

Like JTable, the selected row index in the view may not match the corresponding row in the model, perhaps due to sorting, etc. The getValueAt() method seems a convenient way to call convertRowIndexToModel(). This is common in Swing's separable model architecture, which "collapses the view and controller parts of each component into a single UI (user-interface) object." See A Swing Architecture Overview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文