/** * This takes care of the processing required to validate the quickTextField * input and send out a CAR_ADD event. */ private void processQuickTextField() { String carText = entry.getText().trim(); try { if (carText.length() > 0) Integer.parseInt(carText); TableRowSorter<EntryModel> sorter = new TableRowSorter<EntryModel>((EntryModel)cars.getModel()); sorter.setRowFilter(new QuickEntryFilter(carText)); cars.setRowSorter(sorter); int visible = sorter.getViewRowCount(); if (visible > 0 && visible < 10) cars.setRowSelectionInterval(0, 0); else cars.clearSelection(); } catch(NumberFormatException fe) { log.warning("\bThe provided registration card # is not a number ("+carText+")."); return; } }
private void createPrimerciTable(){ primerciTableModel = new PrimerciTableModel(); primerciTable = new JTable(primerciTableModel); primerciTable.setRowSorter(new TableRowSorter<PrimerciTableModel>(primerciTableModel)); primerciScrollPane = new JScrollPane(primerciTable); listSelModel = primerciTable.getSelectionModel(); adjustInventarColumnWidth(); listSelModel.addListSelectionListener(new ListSelectionListener(){ public void valueChanged(ListSelectionEvent e) { handleListSelectionChanged(); } }); primerciTable.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent ke) { handleKeys(ke); } }); }
ParameterTablePanel(JHVEventParameter[] parameters) { setLayout(new BorderLayout()); ParameterTableModel parameterModel = new ParameterTableModel(parameters); JTable table = new WrappedTable(); table.setModel(parameterModel); table.setAutoCreateRowSorter(true); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setMaxWidth(180); table.getColumnModel().getColumn(0).setPreferredWidth(180); table.getColumnModel().getColumn(1).setPreferredWidth(200); table.getColumnModel().getColumn(1).setCellRenderer(new WrappedTextRenderer()); table.setPreferredScrollableViewportSize(new Dimension(table.getWidth(), 150)); // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<ParameterTableModel> sorter = new TableRowSorter<>(parameterModel); sorter.toggleSortOrder(0); table.setRowSorter(sorter); table.addMouseMotionListener(this); table.addMouseListener(this); add(new JScrollPane(table), BorderLayout.CENTER); }
public MetaDataDialog(ImageLayer layer) { super(ImageViewerGui.getMainFrame(), "Image Information"); exportFitsButton.setEnabled(false); setMetaData(layer); TableRowSorter<TableModel> sorter = new TableRowSorter<>(fitsModel); JTable fitsTable = new JTable(fitsModel); fitsTable.setRowSorter(sorter); setInitFocusedComponent(fitsTable); SearchableUtils.installSearchable(fitsTable); JTextArea basicArea = new JTextArea(basicSB.toString().trim()); basicArea.setEditable(false); JTextArea hvArea = new JTextArea(hvSB.toString().trim()); hvArea.setEditable(false); hvArea.setLineWrap(true); hvArea.setWrapStyleWord(true); content.add(new JScrollPane(basicArea)); content.add(new JScrollPane(fitsTable)); content.add(new JScrollPane(hvArea)); }
protected void initializeLocalVars() { super.initializeLocalVars(); Enumeration<TableColumn> e = getColumnModel().getColumns(); int i = 0; while(e.hasMoreElements() && i < attributes.length) { e.nextElement().setCellRenderer(new NameTableCellRenderer(attributes[i++])); } getColumnModel().getColumn(0).setMinWidth(0); getColumnModel().getColumn(0).setPreferredWidth(3); TableRowSorter<NameTableModel/*<T>*/> sorter = new TableRowSorter<NameTableModel/*<T>*/>((NameTableModel/*<T>*/)getModel()); for (NameUsageAttribute attribute : attributes) { sorter.setComparator(attribute.ordinal(), new NameUsageAttributeComparator(attribute)); } setRowSorter(sorter); setDragEnabled(true); }
protected JComponent createFilterControl() { onlyVisualsCheckBox = new JCheckBox("Show Only Visual Defaults"); onlyVisualsCheckBox.setSelected(true); onlyVisualsCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean showOnlyVisuals = onlyVisualsCheckBox.isSelected(); for(int i = 0; i < tabPane.getTabCount() ; i++) { JScrollPane scrollpane = (JScrollPane)tabPane.getComponentAt(i); JTable table = (JTable)scrollpane.getViewport().getView(); TableRowSorter sorter = (TableRowSorter)table.getRowSorter(); sorter.setRowFilter(showOnlyVisuals? visualsFilter : null); } } }); return onlyVisualsCheckBox; }
protected void initFilters(JTable table) { TableRowSorter sorter = new TableRowSorter(table.getModel()); table.setRowSorter(sorter); if (visualsFilter == null) { visualsFilter = new RowFilter<UIDefaultsTableModel,Integer>() { public boolean include(Entry<? extends UIDefaultsTableModel, ? extends Integer> entry) { UIDefaultsTableModel model = entry.getModel(); Object defaultsValue = model.getValueAt(entry.getIdentifier().intValue(), UIDefaultsTableModel.VALUE_COLUMN); return defaultsValue instanceof Color || defaultsValue instanceof Font || defaultsValue instanceof Icon; } }; } if (onlyVisualsCheckBox.isSelected()) { sorter.setRowFilter(visualsFilter); } }
public TableData(DefaultTableModel defaultTableModel) { super(defaultTableModel); setAutoCreateRowSorter(true); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ((DefaultTableModel) getModel()).setDataVector(new String[1][7], columnName); getTableHeader().setResizingAllowed(true); getColumnModel().getColumn(0).setPreferredWidth(70); getColumnModel().getColumn(1).setPreferredWidth(255); getColumnModel().getColumn(2).setPreferredWidth(215); getColumnModel().getColumn(3).setPreferredWidth(60); getColumnModel().getColumn(4).setPreferredWidth(90); getColumnModel().getColumn(5).setPreferredWidth(100); getColumnModel().getColumn(1).setCellRenderer( new ItalicCellRenderer()); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>( this.getModel()); setRowSorter(sorter); sorter.setComparator(4, new StringComparator()); sorter.setComparator(5, new StringComparator()); sorter.setComparator(6, new StringComparator()); }
public TableData(DefaultTableModel defaultTableModel) { super(defaultTableModel); setAutoCreateRowSorter(true); getTableHeader().setReorderingAllowed(false); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getTableHeader().setResizingAllowed(true); ((DefaultTableModel) getModel()).setDataVector( new String[1][9], columnName); getColumnModel().getColumn(0).setPreferredWidth(70); getColumnModel().getColumn(1).setPreferredWidth(255); getColumnModel().getColumn(2).setPreferredWidth(215); getColumnModel().getColumn(3).setPreferredWidth(60); getColumnModel().getColumn(4).setPreferredWidth(45); getColumnModel().getColumn(5).setPreferredWidth(45); getColumnModel().getColumn(6).setPreferredWidth(70); getColumnModel().getColumn(7).setPreferredWidth(70); getColumnModel().getColumn(8).setPreferredWidth(100); getColumnModel().getColumn(1).setCellRenderer( new ItalicCellRenderer()); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>( this.getModel()); sorter.setComparator(4, new StringComparator()); sorter.setComparator(5, new StringComparator()); sorter.setComparator(6, new StringComparator()); setRowSorter(sorter); }
public TaulaPanela(String mota, String izena) { this.setLayout(new BorderLayout()); if (mota.equalsIgnoreCase("Kautotu")) gureModeloa = new KautotuTaulaModeloa(izena); else gureModeloa = new RankingTaulaModeloa(mota); gureTaula = new ZebraJTable(gureModeloa); gureTaula.setCellSelectionEnabled(true); ListSelectionModel cellSelectionModel = gureTaula.getSelectionModel(); cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); cellSelectionModel.addListSelectionListener(this); gureTaula.setRowSorter(new TableRowSorter<>(gureModeloa)); gureJScrollPane = new JScrollPane(gureTaula); gureJScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); gureJScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); this.add(gureJScrollPane, BorderLayout.CENTER); }
private void updateFilter(String filterText) { filterText = "(?i)" + filterText; @SuppressWarnings({ "rawtypes", "unchecked" }) TableRowSorter<TopLevelTableModel> sorter = (TableRowSorter) table.getRowSorter(); if (filterText.length() == 0) { sorter.setRowFilter(null); } else { try { RowFilter<TopLevelTableModel, Object> rf = RowFilter.regexFilter(filterText, 0, 1); sorter.setRowFilter(rf); } catch (java.util.regex.PatternSyntaxException e) { sorter.setRowFilter(null); } } tableLabel.setText("Matching parts (" + sorter.getViewRowCount() + ")"); }
public EncodeTableModel(String [] headings, List<EncodeFileRecord> records) { this.records = records; List<String> tmp = new ArrayList<String>(); tmp.add(""); // Checkbox heading for(String h : headings) { String heading = h.trim(); if(heading.length() > 0 && !"path".equals(heading)) { tmp.add(heading); } } //tmp.add("path"); columnHeadings = tmp.toArray(new String[tmp.size()]); sorter = new TableRowSorter<EncodeTableModel>(this); sorter.setStringConverter(new TableStringConverter() { @Override public String toString(TableModel model, int row, int column) { final Object value = model.getValueAt(row, column); return value == null ? "" : value.toString(); } }); }
/** * filtra la tabella dei segmenti sui segmenti classificati sul primo * livello * * @param semGui frame * @param level livello */ public static void segmentsTableFilterOnFirstLevel(SemGui semGui, int level) { TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) semGui.getSegmentsTable().getRowSorter(); sorter.setRowFilter(new RowFilter() { @Override public boolean include(RowFilter.Entry entry) { String idSeg = (String) entry.getValue(0); Integer id = Integer.parseInt(idSeg.substring(0, idSeg.indexOf("."))); SemDocument dto = semGui.getTableData().get(id); if (dto != null) { List<ClassificationPath> cpl = dto.getClassPath(idSeg); if (cpl.size() > 0) { if (cpl.get(0).getScore()[level] == 0) { return true; } } else { return true; } } return false; } }); semGui.getSegmentsTable().setRowSorter(sorter); semGui.getStatusSegments().setText("Totale filtrati elementi: " + semGui.getSegmentsTable().getRowCount()); }
/** * gestisce filtri multicampo sulla tabella * * @param table tabella * @param text testo cercato * @param idxs elenco degli id dei campi dove cercare */ public static void filterTable(JTable table, String text, int idxs[]) { TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) table.getRowSorter(); List<RowFilter<TableModel, Integer>> filters = new ArrayList<>(idxs.length); if (text != null && text.length() > 0) { for (int idx : idxs) { table.getColumnModel().getColumn(idx).setCellRenderer(new JTableCellRender(text)); RowFilter<TableModel, Integer> filterC1 = RowFilter.regexFilter("(?i)" + text, idx); filters.add(filterC1); } RowFilter<TableModel, Integer> filter = RowFilter.orFilter(filters); sorter.setRowFilter(filter); } else { sorter.setRowFilter(null); } table.setRowSorter(sorter); }
/** * gestisce filtri diversi su campi diversi sulla tabella * * @since 1.7 * * @param table tabella * @param text testi cercati * @param idxs elenco degli id dei campi dove cercare */ public static void filterTable(JTable table, String text[], int idxs[]) { TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) table.getRowSorter(); List<RowFilter<TableModel, Integer>> filters = new ArrayList<>(idxs.length); if (text != null && text.length > 0) { for (int i = 0; i < idxs.length; i++) { if (text[i] != null && text[i].length() > 0) { LogGui.info("Aggiungo filtro " + text[i] + " su colonna " + idxs[i]); table.getColumnModel().getColumn(idxs[i]).setCellRenderer(new JTableCellRender(text[i])); RowFilter<TableModel, Integer> filterC1 = RowFilter.regexFilter("(?i)" + text[i], idxs[i]); filters.add(filterC1); } } RowFilter<TableModel, Integer> filter = RowFilter.andFilter(filters); sorter.setRowFilter(filter); } else { sorter.setRowFilter(null); } table.setRowSorter(sorter); }
/** * gestisce i filtri sullo stato * * @param filter1 primo filtro * @param filter2 secondo filtro * @param semGui frame */ public static void filterOnStatus(String filter1, String filter2, SemGui semGui) { if (semGui.isIsClassify()) { return; } TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) semGui.getSegmentsTable().getRowSorter(); sorter.setRowFilter(new RowFilter() { @Override public boolean include(RowFilter.Entry entry) { String val = (String) entry.getValue(6); if (filter2 == null) { return filter1.equals(val); } else { return filter1.equals(val) || filter2.equals(val); } } }); semGui.getSegmentsTable().setRowSorter(sorter); semGui.getStatusSegments().setText("Totale filtrati elementi: " + semGui.getSegmentsTable().getRowCount()); }
/** * Create a new Table. * * @param tableModel * The helper to organise the table entries. */ public Table(TableModel tableModel) { super(tableModel); this.tableModel = tableModel; this.tableEntries = tableModel.getTableEntries(); // Add mouseListener to select row on mouse click final Table parent = this; this.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent event) { // selects the row at which point the mouse is clicked Point point = event.getPoint(); int currentRow = parent.rowAtPoint(point); parent.setRowSelectionInterval(currentRow, currentRow); } }); // Enable sorting TableRowSorter<javax.swing.table.TableModel> sorter = new TableRowSorter<>(); sorter.setModel(this.getModel()); this.setRowSorter(sorter); this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); }
/** * Create a new Table. * * @param tableModel * The helper to organise the table entries. */ public BleichenbacherPkcs1Table(BleichenbacherPkcs1TableModel tableModel) { super(tableModel); this.tableModel = tableModel; this.tableEntries = tableModel.getTableEntries(); // Add mouseListener to select row on mouse click final BleichenbacherPkcs1Table parent = this; this.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent event) { // selects the row at which point the mouse is clicked Point point = event.getPoint(); int currentRow = parent.rowAtPoint(point); parent.setRowSelectionInterval(currentRow, currentRow); } }); // Enable sorting TableRowSorter<javax.swing.table.TableModel> sorter = new TableRowSorter<>(); sorter.setModel(this.getModel()); this.setRowSorter(sorter); this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); }
void updateTableStructure() { JTable table = filteredTable.getTable(); TableColumnModel columnModel = table.getColumnModel(); int columnCount = columnModel.getColumnCount(); AnalysisMethod analysisMethod = session.getAnalysisMethod(); if (analysisMethod == AnalysisMethod.HighestAndLowest && columnCount != 3) { columnModel.addColumn(optionalColumn); } if (analysisMethod != AnalysisMethod.HighestAndLowest && columnCount == 3) { optionalColumn = columnModel.getColumn(2); columnModel.removeColumn(optionalColumn); } TableRowSorter<TableModel> sorter = filteredTable.getSorter(); configureSorter(sorter); updateSelectedAttributes(sorter, table.getSelectedRows(), false); }
@SuppressWarnings("unchecked") void updateSelectedAttributes(TableRowSorter<TableModel> sorter, int[] rows) { CompositeMap compositeMap = session.getCompositeMap(); if (compositeMap == null) { return; } NameValuePair<Integer> analysisType = (NameValuePair<Integer>) analysisTypes.getSelectedItem(); int typeIndex = analysisType.getValue(); IntScatterSet filteredDomains = new IntScatterSet(); IntStream rowIndexStream; if (rows.length == 0) { rowIndexStream = IntStream.range(0, filteredTable.getTable() .getRowCount()); } else { rowIndexStream = Arrays.stream(rows); } rowIndexStream.map(i -> sorter.convertRowIndexToModel(i)) .forEach(i -> filteredDomains.add(i)); applyColors(compositeMap, typeIndex, filteredDomains); }
private void updateFilter(String filterText) { filterText = "(?i)" + filterText; @SuppressWarnings({ "rawtypes", "unchecked" }) TableRowSorter<ComponentDefinitionTableModel> sorter = (TableRowSorter) table.getRowSorter(); if (filterText.length() == 0) { sorter.setRowFilter(null); } else { try { RowFilter<ComponentDefinitionTableModel, Object> rf = RowFilter.regexFilter(filterText, 0, 1); sorter.setRowFilter(rf); } catch (java.util.regex.PatternSyntaxException e) { sorter.setRowFilter(null); } } tableLabel.setText("Matching parts (" + sorter.getViewRowCount() + ")"); }
private void updateFilter(String filterText) { filterText = "(?i)" + filterText; @SuppressWarnings({ "rawtypes", "unchecked" }) TableRowSorter<SequenceTableModel> sorter = (TableRowSorter) table.getRowSorter(); if (filterText.length() == 0) { sorter.setRowFilter(null); } else { try { RowFilter<SequenceTableModel, Object> rf = RowFilter.regexFilter(filterText, 0, 1); sorter.setRowFilter(rf); } catch (java.util.regex.PatternSyntaxException e) { sorter.setRowFilter(null); } } tableLabel.setText("Matching sequences (" + sorter.getViewRowCount() + ")"); }
/** * Clear the current filter, i.e., show all proteins. * * @param evt */ private void clearFilterResultsJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearFilterResultsJButtonActionPerformed currentFilterValues = new String[]{"", "", "", "", "", "", "", "", ""}; List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(); RowFilter<Object, Object> allFilters = RowFilter.andFilter(filters); ((TableRowSorter) resultsJTable.getRowSorter()).setRowFilter(allFilters); if (resultsJTable.getRowCount() > 0) { resultsJTable.setRowSelectionInterval(0, 0); } updateResultTableSelection(); saveSettings(false); }
/** * Creates a new panel object. * * @param processList Process list shown in the table. */ public CProcessListPanel(final ProcessList processList) { super(new BorderLayout()); m_processList = processList; final CProcessListModel model = new CProcessListModel(processList); m_sorter = new TableRowSorter<CProcessListModel>(model); m_table = new JTable(model); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m_table.setRowSorter(m_sorter); final JScrollPane scrollPane = new JScrollPane(m_table); scrollPane.setBorder(new TitledBorder("Please select a process to debug")); add(scrollPane); setPreferredSize(new Dimension(200, 200)); }
/** * Creates a new table object. * * @param model Model of the table. * @param helpInfo Context-sensitive help information of the table. */ public CFilteredTable(final CFilteredTableModel<T> model, final IHelpInformation helpInfo) { super(model); m_model = model; m_helpInfo = helpInfo; // All tree tables support sorting m_tableSorter = new TableRowSorter<CFilteredTableModel<T>>(model); // Since the default sorter might not be appropriate for all columns // the model provides sorters for the corresponding columns. for (final Pair<Integer, Comparator<?>> sorter : model.getSorters()) { m_tableSorter.setComparator(sorter.first(), sorter.second()); } setRowSorter(m_tableSorter); }
/** * Creates a new results table. * * @param graph Graph where the highlighting happens. * @param model Provides the results to display. */ public CResultsTable(final ZyGraph graph, final CSpecialInstructionsModel model) { m_graph = graph; m_model = model; m_tableModel = new CResultsTableModel(model); setModel(m_tableModel); final TableRowSorter<CResultsTableModel> sorter = new TableRowSorter<CResultsTableModel>(m_tableModel); sorter.setComparator(CResultsTableModel.TYPE_COLUMN, new CTypeComparator()); sorter.setComparator(CResultsTableModel.ADDRESS_COLUMN, new HexStringComparator()); setRowSorter(sorter); // Make sure that the status cells are colored. getColumnModel() .getColumn(CResultsTableModel.TYPE_COLUMN).setCellRenderer(new CTypeColumnRenderer()); getColumnModel() .getColumn(CResultsTableModel.INSTRUCTION_COLUMN).setCellRenderer(new CMonospaceRenderer()); final InternalSelectionListener listener = new InternalSelectionListener(); getSelectionModel().addListSelectionListener(listener); addMouseListener(listener); }
/** * Creates a new results tracking table. * * @param container Results container from where the results can be read. */ public CTrackingResultsTable(final CTrackingResultContainer container) { m_container = Preconditions.checkNotNull(container, "IE01691: Container argument can not be null"); m_model = new CTrackingResultsTableModel(container); setModel(m_model); m_sorter = new TableRowSorter<TableModel>(m_model); setRowSorter(m_sorter); m_sorter.setComparator(ADDRESS_COLUMN, new LexicalComparator()); // Make sure that the status cells are colored. getColumnModel().getColumn(STATUS_COLUMN).setCellRenderer(new CStatusColumnRenderer()); getColumnModel().getColumn(INSTRUCTION_COLUMN).setCellRenderer(new CMonospaceRenderer()); final InternalSelectionListener listener = new InternalSelectionListener(); getSelectionModel().addListSelectionListener(listener); addMouseListener(listener); }
private void updateClusterTable() { int index = annotationSetCombo.getSelectedIndex(); AnnotationSet annotationSet = annotationSetCombo.getItemAt(index).getValue(); ClusterTableModel clusterModel = new ClusterTableModel(annotationSet); int widths[] = getColumnWidths(clusterTable); clusterTable.setModel(clusterModel); setColumnWidths(clusterTable, widths); TableColumn collapsedColumn = clusterTable.getColumnModel().getColumn(ClusterTableModel.COLLAPSED_COLUMN_INDEX); collapsedColumn.setCellRenderer(new ClusterTableCollapsedCellRenderer(iconManager)); // sort TableRowSorter<TableModel> sorter = new TableRowSorter<>(clusterTable.getModel()); clusterTable.setRowSorter(sorter); List<SortKey> sortKeys = new ArrayList<>(2); sortKeys.add(new RowSorter.SortKey(ClusterTableModel.NODES_COLUMN_INDEX, SortOrder.DESCENDING)); sortKeys.add(new RowSorter.SortKey(ClusterTableModel.CLUSTER_COLUMN_INDEX, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); }
public void setTeamProjectTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) { teamProjectTable.setModel(tableModel); teamProjectTable.setSelectionModel(selectionModel); // Setup table sorter final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); teamProjectTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return teamProjectTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
public void setContextTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) { contextTable.setModel(tableModel); contextTable.setSelectionModel(selectionModel); // Setup table sorter final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); contextTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return contextTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
public void setWorkItemTable(final WorkItemsTableModel tableModel, final ListSelectionModel selectionModel) { workItemTable.setModel(tableModel); workItemTable.setSelectionModel(selectionModel); // Setup table sorter RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); workItemTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return workItemTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
public void setRepositoryTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) { repositoryTable.setModel(tableModel); repositoryTable.setSelectionModel(selectionModel); // Setup table sorter RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); repositoryTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return repositoryTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
/** * Core issue #6539455: table not properly repainted on update (from model). * * Happens if the update is not triggered by an edit in the table itself. If * so, all is well (repaint called for all of the table). If not, repaint is * limited to the cell that has been updated (not even the whole row is * painted) - correct would be to repaint all rows between the old and new * row view index, inclusively. */ public void interactiveSortOnUpdateNotEditing() { final JTable table = new JTable(new AncientSwingTeam()); table.setAutoCreateRowSorter(true); ((TableRowSorter<?>) table.getRowSorter()).setSortsOnUpdates(true); table.getRowSorter().toggleSortOrder(0); JXFrame frame = showWithScrollingInFrame(table, "updates and repaint"); Action edit = new AbstractAction("update first visible") { @Override public void actionPerformed(ActionEvent e) { table.setValueAt("XXX" + table.getValueAt(0, 0), 0, 0); } }; addAction(frame, edit); }
/** * Core issue #6539455: table not properly repainted on update (from model). * * Happens if the update is not triggered by an edit in the table itself. If * so, all is well (repaint called for all of the table). If not, repaint is * limited to the cell that has been updated (not even the whole row is * painted) - correct would be to repaint all rows between the old and new * row view index, inclusively. */ public void interactiveSortOnUpdateNotEditingHack() { final JTable table = new JTableRepaintOnUpdate(); table.setModel(new AncientSwingTeam()); table.setAutoCreateRowSorter(true); ((TableRowSorter<?>) table.getRowSorter()).setSortsOnUpdates(true); table.getRowSorter().toggleSortOrder(0); JXFrame frame = showWithScrollingInFrame(table, "updates and repaint (hacked)"); Action edit = new AbstractAction("update first visible") { @Override public void actionPerformed(ActionEvent e) { table.setValueAt("XXX" + table.getValueAt(0, 0), 0, 0); } }; addAction(frame, edit); }
public OpponentPanel(SimpleTableModel model) { JPanel innerPanel; table = new JTable(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseEventHandler()); sorter = new TableRowSorter<SimpleTableModel>(model); table.setModel(model); table.setRowSorter(sorter); setColumnWidth(table, model.getColumnWidth()); model.addTableModelListener(this); innerPanel = new JPanel(new GridLayout(1, 1)); innerPanel.setBorder(BorderFactory.createTitledBorder(Resource.get("opponent"))); innerPanel.add(new JScrollPane(table)); innerPanel.setPreferredSize(new Dimension(320, 140)); this.setLayout(new BorderLayout()); this.add(innerPanel, BorderLayout.CENTER); }
public GamePanel(GameTableModel model){ this.model = model; table = new JTable(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseEventHandler()); sorter = new TableRowSorter<GameTableModel>(model); table.setModel(model); table.setRowSorter(sorter); setColumnWidth(table, model.getColumnWidth()); TableColumnModel columnModel = table.getColumnModel(); TableColumn colorColumn = columnModel.getColumn(1); colorColumn.setCellRenderer(new ColorCellRenderer()); TableColumn resultColumn = columnModel.getColumn(6); resultColumn.setCellRenderer(new ResultCellRenderer()); model.addTableModelListener(this); this.setLayout(new BorderLayout()); this.add(new JScrollPane(table), BorderLayout.CENTER); }