且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用TableCellRenderer进行Java JTable排序

更新时间:2022-06-08 07:22:00


问题是格式化颜色不能反映排序操作所做的更改。

The problem is that the formating colors don't reflect the change made by the sort operation.

你有渲染器中的逻辑问题。您可能正在使用视图行而不是模型行访问表模型中的数据。

You have a problem with the logic in your renderer. You are probably accessing data in the table model with the "view row" instead of the "model row".

因为您没有发布 SSCCE 演示问题我不能给你一个特定的解决方案只是一般的解决方案。查看以下JTable方法:

Since you didn't post your SSCCE demonstrating the problem I can't give you a specific solution only a general solution. Look at the following JTable methods:

convertRowIndexToModel(int viewRowIndex) 
convertRowIndexToView(int modelRowIndex)  

渲染器收到视图行号。