Disable Column Header sorting on a JTable

Solution 1:

You can use the setSortable method of TableRowSorter as below:

sorter.setSortable(0, false); 

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

Solution 2:

Alternatively, you can set your sortable and non-sortable columns like this:

TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel()) {
    @Override
    public boolean isSortable(int column) {
        if(column < 2)
            return true;
        else 
            return false;
    };
};
table.setRowSorter(sorter);