禁用JTable上的列标题排序 [英] Disable Column Header sorting on a JTable

查看:132
本文介绍了禁用JTable上的列标题排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加分拣机后是否可以在JTable上禁用手动排序?所以我有一个JTable,它附加了以下分类器(基本上在表初始化时按列3排序):

Is it possible to disable manual sorting on a JTable after adding a sorter? So I have a JTable that has the following sorter attached to it (basically sorts by column 3 when the table is initialised):

JTable jTable = new JTable();
RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(jTable.getModel());
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(3, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys); 
jTable.setRowSorter(sorter);

这样可以正常工作,但是用户仍然可以点击表格中的列标题并进行排序我希望禁用的任何列。这可能吗?

This works fine, however the user is still able to click on the column headers in the table and sort by any of the columns, which I want to disable. Is this possible?

推荐答案

您可以使用:

sorter.setSortable(0, false); 

使第0列不可排序。您可以根据您的要求在列上应用它。

to make column 0 non-sortable. You can apply it on the column according to your requirement.

这篇关于禁用JTable上的列标题排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆