Java Code Examples for javax.swing.table.TableRowSorter#sort()
The following examples show how to use
javax.swing.table.TableRowSorter#sort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PanamaHitek_DataBuffer.java From PanamaHitek_Arduino with GNU Lesser General Public License v3.0 | 5 votes |
/** * Permite ordenar los datos en una columna de la tabla que genera la clase * * @param column La columna que se desea ordenar * @param ascending si se desea un orden ascendente o descendente * * @since 3.0.3 */ public void sortColumn(int column, boolean ascending) { TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); if (ascending) { sortKeys.add(new RowSorter.SortKey(column, SortOrder.ASCENDING)); } else { sortKeys.add(new RowSorter.SortKey(column, SortOrder.DESCENDING)); } sorter.setSortKeys(sortKeys); sorter.sort(); }
Example 2
Source File: HighlightTable.java From jmeter-debugger with Apache License 2.0 | 5 votes |
private void setSorter(TableModel model) { TableRowSorter<TableModel> sorter = new TableRowSorter<>(model); sorter.setSortsOnUpdates(true); LinkedList<RowSorter.SortKey> sortKeys = new LinkedList<>(); sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); setRowSorter(sorter); }
Example 3
Source File: SearchResultsFrame.java From Zettelkasten with GNU General Public License v3.0 | 4 votes |
/** * This method initializes the table.<br><br> * - it puts the tab-key as new traversal-key<br> * - sets the autosorter<br> * - displayes the cellgrid<br> * - implements action- and selection-listeners */ private void initTable() { // usually, the tab key selects the next cell in a jTable. here we override this // setting, changing the tab-key to change the focus. // bind our new forward focus traversal keys Set<AWTKeyStroke> newForwardKeys = new HashSet<>(1); newForwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0)); jTableResults.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,Collections.unmodifiableSet(newForwardKeys)); // bind our new backward focus traversal keys Set<AWTKeyStroke> newBackwardKeys = new HashSet<>(1); newBackwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,KeyEvent.SHIFT_MASK+KeyEvent.SHIFT_DOWN_MASK)); jTableResults.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,Collections.unmodifiableSet(newBackwardKeys)); // create new table sorter TableRowSorter<TableModel> sorter = new TableRowSorter<>(); // tell tgis jtable that it has an own sorter jTableResults.setRowSorter(sorter); // and tell the sorter, which table model to sort. sorter.setModel((DefaultTableModel)jTableResults.getModel()); // in this table, the first column needs a custom comparator. try { // sorter for titles sorter.setComparator(1,new Comparer()); // sorter for desktop names sorter.setComparator(5,new Comparer()); // this table has two more columns that should be sorted, the columns with // the entries timestamps. sorter.setComparator(2,new DateComparer()); sorter.setComparator(3,new DateComparer()); } catch (IndexOutOfBoundsException e) { Constants.zknlogger.log(Level.WARNING,e.getLocalizedMessage()); } // get last table sorting RowSorter.SortKey sk = settingsObj.getTableSorting(jTableResults); // any sorting found? if (sk != null) { // create array with sort key ArrayList l = new ArrayList(); l.add(sk); // set sort key to table sorter.setSortKeys(l); // sort table sorter.sort(); } jTableResults.setShowHorizontalLines(settingsObj.getShowGridHorizontal()); jTableResults.setShowVerticalLines(settingsObj.getShowGridVertical()); jTableResults.setIntercellSpacing(settingsObj.getCellSpacing()); jTableResults.getTableHeader().setReorderingAllowed(false); // if the user wants to see grids, we need to change the gridcolor on mac-aqua jTableResults.setGridColor(settingsObj.getTableGridColor()); SelectionListener listener = new SelectionListener(jTableResults); jTableResults.getSelectionModel().addListSelectionListener(listener); jTableResults.getColumnModel().getSelectionModel().addListSelectionListener(listener); }
Example 4
Source File: CruciblePanel.java From Crucible4IDEA with MIT License | 4 votes |
public CruciblePanel(@NotNull final Project project) { super(false); myProject = project; final JBSplitter splitter = new JBSplitter(false, 0.2f); myReviewModel = new CrucibleReviewModel(project); myReviewTable = new JBTable(myReviewModel); myReviewTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myReviewTable.setStriped(true); myReviewTable.setExpandableItemsEnabled(false); final TableColumnModel columnModel = myReviewTable.getColumnModel(); columnModel.getColumn(1).setCellRenderer(new DescriptionCellRenderer()); setUpColumnWidths(myReviewTable); myReviewTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { final int viewRow = myReviewTable.getSelectedRow(); if (viewRow >= 0 && viewRow < myReviewTable.getRowCount()) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final Review review = CrucibleManager.getInstance(myProject).getDetailsForReview((String)myReviewTable. getValueAt(viewRow, myReviewTable.getColumnModel().getColumnIndex(CrucibleBundle.message("crucible.id")))); if (review != null) { openDetailsToolWindow(review); myReviewTable.clearSelection(); } } }, ModalityState.stateForComponent(myReviewTable)); } } }}); final TableRowSorter<TableModel> rowSorter = new TableRowSorter<TableModel>(myReviewModel); rowSorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(4, SortOrder.ASCENDING))); rowSorter.sort(); myReviewTable.setRowSorter(rowSorter); final JScrollPane detailsScrollPane = ScrollPaneFactory.createScrollPane(myReviewTable); final SimpleTreeStructure reviewTreeStructure = createTreeStructure(); final DefaultTreeModel model = new CrucibleTreeModel(); final SimpleTree reviewTree = new SimpleTree(model); new AbstractTreeBuilder(reviewTree, model, reviewTreeStructure, null); reviewTree.invalidate(); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(reviewTree); splitter.setFirstComponent(scrollPane); splitter.setSecondComponent(detailsScrollPane); setContent(splitter); }