0

This is my GUI. I basically want the records in the JTable to be in ascending order of date.

enter image description here


Can you please give an idea how to do this?

Naveen
  • 623
  • 9
  • 20
Dil.
  • 1,996
  • 7
  • 41
  • 68
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). *"I didn't add here my table record loading code because it is not relevant."* Hard code some data for the example. – Andrew Thompson Jan 16 '15 at 09:48
  • [`RowSorter`](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting)? – trashgod Jan 16 '15 at 09:49
  • @Andrew Thompson thank you modified it.. – Dil. Jan 16 '15 at 09:53
  • @trashgod actually there are other records also adding to this table. So I juts can't sort whole column. I need some specific condition like name.equals(listNLB.getSelectedValue().toString()). Because there going to be some records not matching for this condition. – Dil. Jan 16 '15 at 10:03
  • You can combine predicates, as shown [here](http://stackoverflow.com/q/17854854/230513). – trashgod Jan 16 '15 at 10:16
  • *"thank you modified it.."* I'll thank you to follow the links I offer and read them carefully. There is still no MCVE/SSCCE above. – Andrew Thompson Jan 16 '15 at 10:36

2 Answers2

1

Try to see this example, I think it may help you http://www.java2s.com/Tutorial/Java/0240__Swing/SampleSortingTableModel.htm

roeygol
  • 4,908
  • 9
  • 51
  • 88
1

Alternatively this works as well:

JTable.getRowSorter().toggleSortOrder(index);

index refers to the index of the column you want to arrange the records as of.

Naveen
  • 623
  • 9
  • 20