Access tree object in netbeans outline

白昼怎懂夜的黑 提交于 2019-11-28 11:41:41
trashgod

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.

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