Sorting JTable on more than just the values listed in the columns


Posted on 16th Feb 2014 07:03 pm by admin

I have a collection of objects that store (among other things) two integer values. I only want to display one of these values. The displayed value will dictate the sort order of the JTable.

However, I want to break ties with the other, undisplayed, integer value.

I've gone through the trouble of specifying my own Comparator for the TableRowSorter. However, this method doesn't have access to the row index into the table. It is only passed the values in the column that is being sorted, not their position in the column. Without having a reference back to the row index (which I use as an index to the collection of objects) I cannot get the secondary value, unless I also display this value in its own column and sort on Sort Keys.

I don't want to do that, because I feel it clutters up the look of the table.


For example, I have the two sets of numbers

Row Name | Displayed Value | Undisplayed Value
rowA | 7 | 3
rowB | 7 | 5

With this set of data, rowB should be listed above rowA. Any ideas on how to implement this.

I'm pretty new to Swing, so there could be something simple that I'm missing (hopefully).

No comments posted yet

Your Answer:

Login to answer
296 Like 12 Dislike
Previous forums Next forums
Other forums

MS Exchange 2007 integration with ECC 6.0
Hello Experts,
We have ECC 6.0 and MS Exchange 2007. We need to integrate ECC 6 and MS Excha

Parse Error
Hi Guys,

I have a function in my class which returns a string link variable. The problem is i

IP Logger for Voting Script
Can anybody help me place an IP logger into my voting script?
I know that maybe it is not as secu

tell csv import script to ignore blank rows?
Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the e

Filtering an Array Based on Value
I have a very simple script set up that pulls data from a database and is output using this code:

How to separate records and ORDER BY
Let say i have 100 records and displayed in one page, then i want to get the records from 50-100 and

If a form submits back to same page do you need to use $get
IM trying to pass page number and year that was selected back to the same page.

i have this c

Calling a Procedure with IN & OUT Parameters
Hello,

I usually call my procedures using the following way

declare variable e

Displaying pictures
i have worked my way through storing images in directory and storing the location in mySQL db.Now i

issues verifying if user is logged in
I am having issues when a user logs in via asp Login control, the IsAuthenticated still seems to com

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash