List of utility methods to do JTable Row Sort
RowSorterListener | addSingleSortableColumnListener( @Nonnull RowSorter extends TableModel> rowSorter) Add a RowSorterListener to the rowSorter that prevents multiple columns from being considered while sorting. Objects.requireNonNull(rowSorter, "rowSorter must be nonnull."); RowSorterListener listener = new RowSorterListener() { List<? extends SortKey> priorSortKeys = new ArrayList<>(); @Override public void sorterChanged(RowSorterEvent e) { if (e.getType().equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) { RowSorter<?> source = e.getSource(); List<? extends SortKey> newSortKeys = new ArrayList<>(source.getSortKeys()); ... |
void | applyRowSorter(JTable table) apply Row Sorter @SuppressWarnings({ "rawtypes", "unchecked" }) TableRowSorter<?> sorter = new TableRowSorter(table.getModel()); sorter.setSortsOnUpdates(true); table.setRowSorter(sorter); |
TableRowSorter | createTableRowSorter(Class create Table Row Sorter final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); final Comparator<T> comp = new Comparator<T>() { @Override public int compare(T o1, T o2) { return o1.compareTo(o2); }; for (int i = 0; i < model.getColumnCount(); i++) { ... |
void | filt(ArrayList filt ArrayList<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(2); RowFilter<Object, Object> textFilter = null; RowFilter<Object, Object> levelFilter = null; if (text.length() != 0) { textFilter = RowFilter.regexFilter(text); if (!selectedLevel.isEmpty()) { String levels = "["; ... |
SortOrder | getSortOrder(@Nonnull RowSorter extends TableModel> rowSorter, int column) Get the sort order for a column given a RowSorter for the TableModel containing the column. for (SortKey key : rowSorter.getSortKeys()) { if (key.getColumn() == column) { return key.getSortOrder(); return SortOrder.UNSORTED; |
void | jtable$setAutoCreateRowSorter(JTable table) jtablset Auto Create Row Sorter try { Method e = table.getClass().getMethod("setAutoCreateRowSorter", new Class[] { Boolean.TYPE }); e.invoke(table, new Object[] { Boolean.valueOf(true) }); } catch (Exception var2) { var2.printStackTrace(); |
void | setSortOrder(@Nonnull RowSorter extends TableModel> rowSorter, int column, @Nonnull SortOrder sortOrder) Set the sort order for a table using the specified column given a RowSorter for the TableModel containing the column. List<SortKey> keys = new ArrayList<>(); if (!sortOrder.equals(SortOrder.UNSORTED)) { keys.add(new RowSorter.SortKey(column, sortOrder)); rowSorter.setSortKeys(keys); |
void | tryToEnableRowSorting(JTable listTbl) try To Enable Row Sorting TableRowSorter sorter = new TableRowSorter(listTbl.getModel());
listTbl.setRowSorter(sorter);
|