JXTreeTable 和 JComboBox 单元格编辑器
如何在 JXTreeTable
? 你能给我一个有效的例子吗?
How can I use JComboBox
as cell editor in JXTreeTable
? Can you give me a working example please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了
JXTreeTable
用于显示分层数据的列之外,您可以使用以下代码将JComboBox
使用单元格编辑器用于所有列。例如:
即您不能将
JComboBox
用于JXTreeTable
用于显示分层数据的列。在
JXTreeTable
java doc 中他们提到了这一点,JXTreeTable内部创建了
TreeTableCellEditor
,用于显示分层数据。TreeTableModel
提供方法getHierarchicalColumn()
其中您可以指定使用哪个列来显示分层数据现在,如果您想在第一列提供
JComboBox
(第 0 个位置列默认为分层列),那么您有使用 TreeTableModel 提供不同的列索引,否则您必须移动您的列(我这边推荐)。为分层数据提供不同列的代码
预览
注意:我提供了此解决方案,以便您可以使用最少的自定义代码来实现您的解决方案。 可以有另一种方法,但我个人认为这个解决方案很容易实现
You can use
JComboBox
using cell editor for all column using below code except a column whichJXTreeTable
uses to display hierarchical data.Ex:
i.e. you can not use
JComboBox
for a column whichJXTreeTable
uses to display hierarchical data.In
JXTreeTable
java doc they have mention that,JXTreeTable creates
TreeTableCellEditor
internally which is used to display hierarchical data.TreeTableModel
provides methodgetHierarchicalColumn()
in which you can specify which colum uses to display hierarchical dataNow if you want to provide
JComboBox
at first column(0th position column is by default hierarchical column) then you have to provide different column index using TreeTableModel otherwise you have to shift your column(recommended from my side).Code to provide different column for hierarchical data
Preview
NOTE: I have provided this solution such that you can achieve your solution with minimum customization code. There can be another way but I personally find this solution very easy to implement