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

Adding to the next element in a multidimensional array
Hi, I'm trying to add a value to $node->field_spaces['nid'] where x is the next available spo

Material Master Update through BAPI - Follow up material not updated
Hi Experts,

I am updating the material master through a custom transaction using the BAPI

Session login issue
I'm wondering how to fix a problem I'm having with a session-based login system

Say I go to h

Advice on how to delete a mysql row using my form
Hi,

I am very new to php and am struggling to work out how to delete a portfolio item (a row

PHP IMAGE UPLOAD SCRIPT
Hi for the last week i have been looking for scripts that will upload a photo to a certain folder wh

Transaction variant for VA02 not working
My requirement is to have transaction for user to only add the output and print a sales order.

Problem with HTTP Caching...?
Hi there, im trying to implement caching. But it doesn't always work.
I post it here because ther

I think i'm using the syntax incorrectly
Hi Everyone!

I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hop

Coefficient of a Restitution Hints
Hello. I was wondering if anyone can give me hints on how to write this program...

The coeffi

How to use Substr
I want to check for the word CATEGORY: inside a string which can be CATEGORY: ITEM
and remove the

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