Access tree object in netbeans outline

后端 未结 1 1415
南笙
南笙 2020-12-10 20:32

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

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

相关标签:
1条回答
  • 2020-12-10 21:09

    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.

    0 讨论(0)
提交回复
热议问题