2012-08-08 56 views
2

我想激發一個事件,該事件表示給定的列值已全部更改,即列X中的某處,某些值已更改。我如何能做到這一點,因爲所有的事件無論是關注單元格,行或整個數據表......在AbstractTableModelJTable - 激活列數據更改事件

回答

5

看,它看起來像構建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. (...) 
+0

+1你是對的 - 我的評論是錯誤的:-) – kleopatra 2012-08-08 09:45:22

1

個人而言,我只希望觸發一個事件地說,如果它只是指示所需刷新表整個表發生了變化。

+0

你將失去​​表中選定的行。 – 2013-11-05 20:59:18