Multiple Column Sortings in JTable

I know that I JTablecan sort by one column. But is it possible to allow sorting multiple columns or do I need to write the code myself?

+5
source share
5 answers

You can sort by multiple columns by specifying more than one sort key when calling setSortKeysin RowSorterwhich you are using.

+9
source

You should be able to install the associated TableRowSorter and Comparator. Example:

TableModel myModel = createMyTableModel();
JTable table = new JTable(myModel);
TableRowSorter t = new TableRowSorter(myModel);
t.setComparator(column that the comparator works against, Comparator<?> comparator);
table.setRowSorter(new TableRowSorter(myModel));
+1
source

JXTable. JXTable - JTable, , , JTable . JDNC/SwingLabs.

+1

ETable netbeans.
org-netbeans-swing-outline.jar
Google google, . ETable Outline (TreeTable), , .

+1

" , Jtable . ?"

Sorting and filtering the table is controlled by the sorter object. The easiest way to provide a sorter object is to set the autoCreateRowSorter property to true:

JTable table = new JTable();
table.setAutoCreateRowSorter(true);

This action defines the row sorter, which is an instance of javax.swing.table.TableRowSorter.

+1
source

All Articles