当用户单击标题时,如何防止对Java Swing JTable列进行排序? [英] How do I prevent a Java Swing JTable column from being sorted when the user click on the header?
本文介绍了当用户单击标题时,如何防止对Java Swing JTable列进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含几列的JTable.我想使某些列无法排序.我该怎么做?我一直使用Java 1.4,因此不能使用TableRowSorter,因为直到1.6才引入TableRowSorter.
I have a JTable that has several columns. I wanted to make some of the columns unsortable. How do I do it? I am stuck using Java 1.4 so using TableRowSorter isn't an option since it wasn't introduced until 1.6.
推荐答案
-
仅将
RowSorter
应用于所需的列apply
RowSorter
to the desired column(s) only(例如,只有伪代码,所有内容都经过硬编码,例如,必须覆盖ColumnModel中的列)
(for example, only pseudo_code, everything is there hardcoded as example, have to override columns from ColumnModel)
if (column >= 0 && column < getModelWrapper().getColumnCount() && isSortable(column)) {
使用
if (column >= 0 && column <=1 /*getModelWrapper().getColumnCount()*/ && isSortable(column)) {
在
public void toggleSortOrder(int column) {
然后第二列不可排序
- 如果不帮您提供更好的帮助,请尽早发布 SSCCE 演示您的问题
- if not help you for better help sooner post an SSCCE demonstrated your issue
这篇关于当用户单击标题时,如何防止对Java Swing JTable列进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文