访问 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看今天宣布新的 Swing 树表< /a>.看起来作者正在创建数据模型,因此< em>响应节点选择应该会有所帮助。我在 NetBeans 6.8 中找到了 org.netbeans.swing.outline.Outline 类:
附录:
请注意,
Outline
源自JTable
,因此 如何使用表格:用户选择 可能会有所帮助。根据上面引用的示例,这里有一个侦听器,它显示当节点展开和折叠时行号的明显变化,并且选择保持不变: .html" rel="nofollow noreferrer">临时,您可以查看
OutlineModel
和DefaultOutlineModel
。前者实现了TreeModel
和TableModel
并提供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:Addenda:
Note that
Outline
descends fromJTable
, 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:Although provisional, you might look at
OutlineModel
andDefaultOutlineModel
. The former implements bothTreeModel
andTableModel
and offersTreePathSupport
; 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. ThegetValueAt()
method seems a convenient way to callconvertRowIndexToModel()
. 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.