[英]JXTable - how to update highlighters on sorting the table
我有一個帶有自定義表模型的JXTable。 我添加了2個ColorHighlighter和自定義的HighlightPredicate。
問題是,當我單擊列標題時,表格將對行進行排序,但熒光筆的顯示仍與舊視圖相同。
對表格進行排序后,如何更新突出顯示的狀態?
正如@kleopatra所述,我查看了我的謂詞:
HighlightPredicate spakowany = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
TableModel tableModel = table.getModel();
if (tableModel instanceof StanTableModel) {
StanTableModel stanTableModel = (StanTableModel) tableModel;
// int rowIndex = adapter.row; <- this was the issue
int rowIndex = adapter.convertRowIndexToModel(adapter.row);
StanTableRow myCustomRow = stanTableModel.getRow(rowIndex);
if ((myCustomRow.isSpakowany()) {
return true;
}
}
return false;
}
};
並使用@mKorbel想法:
原為:
int rowIndex = adapter.row;
就是現在:
int rowIndex = adapter.convertRowIndexToModel(adapter.row);
現在就可以了。
StanTableModel是我的自定義表格模型。 它具有getRow()函數並返回一個StanTableRow對象,而該對象又具有isSpakowany()函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.