Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to sort column when I click on table header, all row are true except the first column is integer number. The result I received like:
1
10
11
2
22
3
31
....
I have try getColumnClass() but it didn't work.
My code here:
model = new DefaultTableModel(vData, vTitle)
            {
                Class[] types = {Integer.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class};
                @Override
                public Class getColumnClass(int columnIndex) {
                    return this.types[columnIndex];
                }

                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };


What I have tried:

I tried a lot but it still fail. Please help me!!!
Posted
Updated 19-Jan-22 0:54am
Comments
Richard MacCutchan 19-Jan-22 5:29am    
The content of that column must be strings, not integers. That is the result you get when sorting numbers that are stored as character strings, rather than integer values.

1 solution

It seems that the underlying column of vData is String that is creating the issue. The solution is simple.

* Your DB Query should return the data as integer
* Your model should save this column's data as integer

And that's it. Your Sorting should work as expected
 
Share this answer
 
Comments
Member 15493982 19-Jan-22 7:18am    
thanks you so much!!! I'm done with this issue.
Can I ask you one question?
_Asif_ 19-Jan-22 7:48am    
yes, put new Question so that every body can look and respond
Member 15493982 19-Jan-22 7:55am    
I use filter on jtable, but sometime when I enter text on jtextfield to filter, it has exception like: index X out of bounds for length 0 (X is a number). I don't know why. I saw Keyboard focus manager in exception too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900