×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Massimo Zappino
Added: Jan 15, 2016 1:08 PM
Modified: Aug 27, 2017 3:33 PM
Views: 35
How to sort a specific JTable column programmatically
  1. TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel());
  2. table.setRowSorter(sorter);
  3. ArrayList<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
  4.  
  5. int columnIndexToSort = 1;
  6. sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING));
  7.  
  8. sorter.setSortKeys(sortKeys);
  9. sorter.sort();

1 comment

Jon Good 1 year ago
Nice piece of code, thanks

Write a comment