• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about TableRowSorter

 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using TableRowSorter for a table. It is mostly easy to set up-



but it has a major failing- when the table has empty rows, they appear at the top of the table. I naively thought that I could provide a custom comparator





No such luck, the code for TableRowSorter does not use the custom comparator for null fields.



I tried a crude workaround, I reversed the order of my comparator,



so there is at least a way to get the numbers in the order I want and the blank rows at the bottom. But it would be nicer if the arrows were consistent with the sort.

Are there better other alternates than copying the TableRowSort class so I can change the two offending lines?
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Swanson wrote:No such luck, the code for TableRowSorter does not use the custom comparator for null fields.

I'm afraid I'm no GUI expert, but that does make sense to me; otherwise you're likely to get NPE's cropping up in deeply embedded code.

I guess my question is: why are these rows (or column fields) null?

Winston
 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorting the rows was added as a requirement after I finished coding something up that allowed a user to interactively enter data into a table. I originally set things up display a table with the number of rows that were likely to be needed. Then, if the user needed more, they could add (or delete) rows from a popup menu. So there will typically be at least one empty row for adding the next piece of data.

I also notice once TableRowSorter is active, it sorts automatically when I add a row, which is not quite what the user is expecting (i.e. they might want to insert a row, enter data, then sort). So there are a few other tricks I may need to learn about TableRowSorter. I'm also looking to have the table initially display in 'sort' mode as if the user had clicked on the table header. I think that might be doable, still experimenting on that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic