Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable and it's SortKeys - several SortKeys but only on column sorted?

800390Aug 15 2010 — edited Aug 29 2010
Hello,

I have a question about the JTable, it's RowSorter/SortKeys and the behavior, when the user clicks on the table headers.

When the user clicks on a header, that header gets sorted - first ascrending, second descrending.

When I now add the following code to the JTable, overriding the "paintComponent" method:
@Override
protected void paintComponent( Graphics g ) {
	super.paintComponent( g );
	
	for ( RowSorter.SortKey sortKey : getRowSorter().getSortKeys() )
		System.out.println( "sortKey.getColumn(): " + sortKey.getColumn() + ", SortOrder: " + sortKey.getSortOrder() );
}
I get this output:
sortKey.getColumn(): 0, SortOrder: ASCENDING
When I click on the first header again, the output is
sortKey.getColumn(): 0, SortOrder: DESCENDING
When I now click on the second header, the output is
sortKey.getColumn(): 1, SortOrder: ASCENDING
sortKey.getColumn(): 0, SortOrder: DESCENDING
BUT now the rendering of the table shows, that only the second header is sorted (indicated by that little row, and the second header's background is light blue under the Windows L&F). But I have obviously two SortKeys - should the table not be sorted with those two keys, and shouldn't that be indicated by two little arrows, one in the first and the other in the second header?

The table seems only to take the first SortKey in the list into account, the second seems to be ignored, is that right?

Is there any property of the JTable class I have to set, so the sorting is done with two or more columns, also?


Thanks a lot for your help


Best reagards,
Timo
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2010
Added on Aug 15 2010
5 comments
861 views