访问netbeans大纲中的树对象 [英] Access tree object in netbeans outline

查看:172
本文介绍了访问netbeans大纲中的树对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

您可以查看 今天宣布新的Swing Tree Table 。看起来作者是 创建数据模型 响应节点选择 应该会有所帮助。我在NetBeans 6.8中找到了类 org.netbeans.swing.outline.Outline


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

附录:

请注意大纲来自 JTable ,所以 如何使用表格:用户选择 可能会有所帮助。基于上面引用的示例,这里是一个监听器,它显示了当节点展开和折叠时行号的明显变化,并且选择保持不变:

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

虽然临时,您可以查看 OutlineModel DefaultOutlineModel 。前者实现 TreeModel TableModel 并提供 TreePathSupport ;后者提到TableModelEvent和TreeModelEvent之间的阻抗不匹配。

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."

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

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.

这篇关于访问netbeans大纲中的树对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆