• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about sorting a Jtable.  RSS feed

 
Ubaldo Robledo
Greenhorn
Posts: 22
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey buddies.

I have a Question for you all. how can i sort a Jtable, If i have in a certain column Strings and Integers, but I don't want to sort like string.
example:

ID |
----------
1
11
2
213
22
MOSTR
MOSTIR

i dont want this to happen when i sort this column, do you know a work around guys?

I'm using

table.setAutoCreateRowSorter(true);

I'll really appreciate any help, Thank you!
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you read the swing tutorial on sorting JTables at http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting.

Create your own sorter that checks for numeric values and if they are both numeric sort them according to their numeric order rather than their alphabetic order. Where you have one value which is numeric and one which isn't the numeric value comes first.
 
Ubaldo Robledo
Greenhorn
Posts: 22
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let me take a look! thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!