用单独的行 header table 在 Table 架构中重建 JTable 结构
Rebuild JTable structure in Table architecture with separate row header table
我有三种不同的 table 结构,每一种都在一个 JScrollPane
中。每个 table 都是用单独的行 header 实现的,这些行不会沿水平方向滚动(与 here 的完成方式非常相似)。与 link 中一样,我写了两个自定义 TableColumnModels
,它们要么删除第一行,要么删除除第一行以外的所有行。一个 JTable
只包含行 header 列,另一个包含剩余数据共享相同的 TableModel
。但是,我正在努力处理 autocreateColumnsFromModel
标志和相应的方法 createDefaultColumnsFromModel()
。当我向 table 添加新条目时(在我的 GUI 中通过单击调用该功能的按钮),必须更新其他 table(因此,调用 AbstractTableModel.fireTableStructureChanged()
) .我现在的问题是,随着 table 的重建,行 header 列是 re-added 作为 table 的常规列(因为在我看来,createDefaultColumnsFromModel()
仅使用 TableModel
重建 table 并忽略要删除哪一列和使用哪一列的 TableColumnModels
约束。
我确实发现 this article 有趣的是谈论那个问题,说明
This requires that you manage the TableColumns of the main table on your own, otherwise JTable will re-introduce the header column into the main table
...,这正是我正在发生的事情。但这意味着什么,要我自己管理主要 table 的 TableColumns
?我如何使用 TableColumnModel
来重建 table 结构,它会负责在 table 中显示哪些列?
问题不在 fireTableStructureChanged()
方法或 createDefaultColumnsFromModel()
中。但是 TableColumnModel
,其 addColumn()
方法特定于 rowHeaderTable 和 mainTable(参见 this implementation)需要重新实例化。那是因为检查是否只有第一列或只有第一列以外的所有内容都应该添加到 table 的标志需要重置。
使用这个新的 tableColumnModel
,可以调用 createDefaultColumnsFromModel()
并成功更新 table。
我有三种不同的 table 结构,每一种都在一个 JScrollPane
中。每个 table 都是用单独的行 header 实现的,这些行不会沿水平方向滚动(与 here 的完成方式非常相似)。与 link 中一样,我写了两个自定义 TableColumnModels
,它们要么删除第一行,要么删除除第一行以外的所有行。一个 JTable
只包含行 header 列,另一个包含剩余数据共享相同的 TableModel
。但是,我正在努力处理 autocreateColumnsFromModel
标志和相应的方法 createDefaultColumnsFromModel()
。当我向 table 添加新条目时(在我的 GUI 中通过单击调用该功能的按钮),必须更新其他 table(因此,调用 AbstractTableModel.fireTableStructureChanged()
) .我现在的问题是,随着 table 的重建,行 header 列是 re-added 作为 table 的常规列(因为在我看来,createDefaultColumnsFromModel()
仅使用 TableModel
重建 table 并忽略要删除哪一列和使用哪一列的 TableColumnModels
约束。
我确实发现 this article 有趣的是谈论那个问题,说明
This requires that you manage the TableColumns of the main table on your own, otherwise JTable will re-introduce the header column into the main table
...,这正是我正在发生的事情。但这意味着什么,要我自己管理主要 table 的 TableColumns
?我如何使用 TableColumnModel
来重建 table 结构,它会负责在 table 中显示哪些列?
问题不在 fireTableStructureChanged()
方法或 createDefaultColumnsFromModel()
中。但是 TableColumnModel
,其 addColumn()
方法特定于 rowHeaderTable 和 mainTable(参见 this implementation)需要重新实例化。那是因为检查是否只有第一列或只有第一列以外的所有内容都应该添加到 table 的标志需要重置。
使用这个新的 tableColumnModel
,可以调用 createDefaultColumnsFromModel()
并成功更新 table。