且构网

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

JTable的行条目少于显示和排序问题

更新时间:2022-06-09 07:24:19

如果您希望能够编辑这些空行,那么我想唯一的方法是覆盖DefaultRowSortergetComparator(column)方法.

If you want to be able to edit these empty rows, then I guess the only way is to override DefaultRowSorters getComparator(column) method.

编辑我以为您可以覆盖getComparator(),或为每个列设置一个Comparator,以便它检查值之一是否为null等. ,因为DefaultRowSorter中存在null检查,并且还有其他问题.

EDIT I thought you could either override getComparator(), or set a Comparator to each column so that it checks if one of the values is null etc. I tried it, it didn't work, because there are null checks in the DefaultRowSorter, and there are other problems.

不幸的是,DefaultRowSorter中的大多数内容都是私有的,因此自定义的空间不大.如果您想要这种行为,则必须编写自己的RowSorter实现.我建议您仅在此功能对您的应用绝对重要时才采用这种方法.

Unfortunately, most stuff in DefaultRowSorter is private, so there's not much room for customising. If you want this behaviour, you'd have to write your own implementation of RowSorter. I'd recommend you to take this approach only if this functionality is absolutely critical to your app.