我想触发一个事件,该事件表示给定的列值已全部更改,即在列X的某处,某些值已更改。我怎么能这样做,因为所有事件都涉及单元格,行或整个数据表......
答案 0 :(得分:5)
查看AbstractTableModel
,看起来明确构建TableModelEvent
可能会有效:
model.fireTableChanged(new TableModelEvent(model, 0, lastRow, columnIndex,
TableModelEvent.UPDATE));
另请参阅TableModelEvent
的javadoc:
/**
* Depending on the parameters used in the constructors, the TableModelevent
* can be used to specify the following types of changes: <p>
*
* <pre>
* TableModelEvent(source); // The data, ie. all rows changed
* TableModelEvent(source, HEADER_ROW); // Structure change, reallocate TableColumns
* TableModelEvent(source, 1); // Row 1 changed
* TableModelEvent(source, 3, 6); // Rows 3 to 6 inclusive changed
* TableModelEvent(source, 2, 2, 6); // Cell at (2, 6) changed
* TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted
* TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted
* </pre>
*
* It is possible to use other combinations of the parameters, not all of them
* are meaningful. (...)
答案 1 :(得分:1)
就个人而言,如果只是为了指示表需要刷新,我只会触发一个事件来说整个表已经改变了。