List of usage examples for javax.swing.table TableRowSorter TableRowSorter
public TableRowSorter(M model)
TableRowSorter
using model
as the underlying TableModel
. From source file:com.view.PortfolioManagerWindow.java
private void PMOrderHistoryFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMOrderHistoryFilterActionPerformed final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMOrderHistoryTable.getModel()); PMOrderHistoryTable.setRowSorter(sorter); String text = FilterTextPMOrderHistory.getText(); if (text.length() == 0) { sorter.setRowFilter(null);/*from w w w . j ava2 s . c o m*/ } else { sorter.setRowFilter(RowFilter.regexFilter(text)); } }
From source file:com.view.PortfolioManagerWindow.java
private void ClearFilterPMPendingOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMPendingOrderActionPerformed FilterTextPMPending.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMPendingOrdersTable.getModel()); PMPendingOrdersTable.setRowSorter(sorter); sorter.setRowFilter(null);/*from w w w. j ava2 s .c om*/ }
From source file:com.view.PortfolioManagerWindow.java
private void ClearFilterPMOrderHistoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMOrderHistoryActionPerformed FilterTextPMOrderHistory.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMOrderHistoryTable.getModel()); PMOrderHistoryTable.setRowSorter(sorter); sorter.setRowFilter(null); // TODO add your handling code here: }
From source file:com.view.PortfolioManagerWindow.java
private void ClearFilterPMEODActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMEODActionPerformed // TODO add your handling code here: FilterTextPMEOD.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMEODBoughtTable.getModel()); PMEODBoughtTable.setRowSorter(sorter); final TableRowSorter<TableModel> sorter2 = new TableRowSorter<TableModel>(PMEODSoldTable.getModel()); PMEODSoldTable.setRowSorter(sorter2); sorter.setRowFilter(null);//w w w .j a v a 2 s. c o m sorter2.setRowFilter(null); }
From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java
private JTable getCodeBaseTable() { if (codeBaseTable == null) { CodeBaseTableModel codeBaseTableModel = new CodeBaseTableModel(peterDwarfPanel); codeBaseTable = new JTable(); codeBaseTable.setModel(codeBaseTableModel); sorter = new TableRowSorter<TableModel>(codeBaseTableModel); codeBaseTable.setRowSorter(sorter); codeBaseTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); codeBaseTable.getColumnModel().getColumn(0).setPreferredWidth(100); codeBaseTable.getColumnModel().getColumn(1).setPreferredWidth(100); codeBaseTable.getColumnModel().getColumn(2).setPreferredWidth(400); codeBaseTable.getColumnModel().getColumn(3).setPreferredWidth(1500); codeBaseTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { codeBaseTableMouseClicked(evt); }//from ww w. j av a 2 s . co m }); } return codeBaseTable; }
From source file:dataviewer.DataViewer.java
private void renderData(DefaultTableModel model) { tb_data.setVisible(false);//w w w .ja va 2s . c o m tb_data.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 == 0 ? Color.WHITE : new Color(240, 240, 240)); if (table.isCellSelected(row, column)) { c.setBackground(new Color(200, 0, 0)); c.setForeground(Color.white); } else if (table.isRowSelected(row)) { c.setBackground(new Color(0, 0, 200)); c.setForeground(Color.white); } else { c.setForeground(Color.black); } return c; } }); tb_data.setGridColor(new Color(220, 220, 220)); tb_data.setShowVerticalLines(true); tb_data.setModel(model); for (int i = 0; i < model.getColumnCount(); ++i) { if (model.getColumnName(i).equals("_N_")) { TableRowSorter trs = new TableRowSorter(model); trs.setComparator(i, new IntComparator()); tb_data.setRowSorter(trs); } } for (int j = 0; j < tb_data.getColumnCount(); j++) { int width = 0; TableColumn col = tb_data.getColumnModel().getColumn(j); TableCellRenderer renderer = tb_data.getTableHeader().getDefaultRenderer(); Component comp = renderer.getTableCellRendererComponent(tb_data, col.getHeaderValue(), false, false, 0, 0); width = Math.max(comp.getPreferredSize().width, width); for (int i = 0; i < tb_data.getRowCount(); i++) { renderer = tb_data.getCellRenderer(i, j); comp = tb_data.prepareRenderer(renderer, i, j); width = Math.max(comp.getPreferredSize().width, width); } tb_data.getColumnModel().getColumn(j).setPreferredWidth(width + 20); } tb_data.setVisible(true); }
From source file:NewGUI.Statistics.java
private void menuItemSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSortActionPerformed // TODO add your handling code here: popupTable.setVisible(false);// w w w . j ava 2s . c o m int column = tbList.getSelectedColumn(); //tbList.sorterChanged(new RowSorterEvent(sorter)); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tbList.getModel()); tbList.setRowSorter(sorter); tbList.getRowSorter().toggleSortOrder(column); }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Create detail frames shown after calculation *//*from w w w. j a v a 2s. co m*/ private void buildDetailedStatistics(HashMap<Village, String> attackMappings, List<Village> pNotAssignedVillages) { // <editor-fold defaultstate="collapsed" desc="Build not assigned source table"> Collections.sort(pNotAssignedVillages); DefaultTableModel sourcesModel = new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Spieler", "Dorf" }) { private Class[] cTypes = new Class[] { Tribe.class, Village.class }; @Override public Class getColumnClass(int columnIndex) { return cTypes[columnIndex]; } }; for (Village notAssigned : pNotAssignedVillages) { Tribe t = notAssigned.getTribe(); if (t == null) { sourcesModel.addRow(new Object[] { Barbarians.getSingleton(), notAssigned }); } else { sourcesModel.addRow(new Object[] { t, notAssigned }); } } jNotAssignedSourcesTable.setModel(sourcesModel); TableRowSorter<TableModel> sourcesSorter = new TableRowSorter<TableModel>(sourcesModel); jNotAssignedSourcesTable.setRowSorter(sourcesSorter); DefaultTableCellRenderer headerRenderer = new SortableTableHeaderRenderer(); for (int i = 0; i < jNotAssignedSourcesTable.getColumnCount(); i++) { jNotAssignedSourcesTable.getColumn(jNotAssignedSourcesTable.getColumnName(i)) .setHeaderRenderer(headerRenderer); } jNotAssignedSourcesTable.revalidate(); //</editor-fold> // <editor-fold defaultstate="collapsed" desc="Build attacks per target table"> DefaultTableModel tableModel = new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Spieler", "Dorf", "Angriffe" }) { Class[] types = new Class[] { Tribe.class, Village.class, String.class }; @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }; List<Village> notFullTargets = new LinkedList<Village>(); Iterator<Village> keys = attackMappings.keySet().iterator(); while (keys.hasNext()) { Village key = keys.next(); Tribe t = key.getTribe(); //int notAssignedAmount = attackMappings.get(key); String attackCount = attackMappings.get(key); String[] split = attackCount.split("/"); int notAssignedAmount = Integer.parseInt(split[1]) - Integer.parseInt(split[0]); if (t != Barbarians.getSingleton()) { tableModel.addRow(new Object[] { t, key, attackCount }); } else { tableModel.addRow(new Object[] { "Barbaren", key, attackCount }); } if (notAssignedAmount > 0) { notFullTargets.add(key); } } jTargetDetailsTable.setModel(tableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); jTargetDetailsTable.setRowSorter(sorter); DefaultTableCellRenderer coloredRenderer = new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, row); String t = ((DefaultTableCellRenderer) c).getText(); ((DefaultTableCellRenderer) c).setText(t); DefaultTableModel model = (DefaultTableModel) table.getModel(); int r = table.convertRowIndexToModel(row); String sVal = (String) model.getValueAt(r, 2); String[] split = sVal.split("/"); long max = Long.parseLong(split[1]); long v = Long.parseLong(split[0]); long diff = max - v; Color back = Color.RED; if (v == 0) { //color stays red } else if (v == max) { back = Color.GREEN; } else { float posv = 100.0f * (float) diff / (float) max; posv = ((int) posv / 10) * 10; posv /= 100; Color LAST_SEGMENT = new Color(255, 100, 0); int red = (int) Math.rint( (float) LAST_SEGMENT.getRed() * (1.0f - posv) + (float) Color.YELLOW.getRed() * posv); int green = (int) Math.rint((float) LAST_SEGMENT.getGreen() * (1.0f - posv) + (float) Color.YELLOW.getGreen() * posv); int blue = (int) Math.rint( (float) LAST_SEGMENT.getBlue() * (1.0f - posv) + (float) Color.YELLOW.getBlue() * posv); if (red < 0) { red = 0; } if (green < 0) { green = 0; } if (blue < 0) { blue = 0; } if (red > 254) { red = 254; } if (green > 254) { green = 254; } if (blue > 254) { blue = 254; } back = new Color(red, green, blue); } DefaultTableCellRenderer renderer = ((DefaultTableCellRenderer) c); if (!isSelected) { renderer.setBackground(back); } return c; } }; jTargetDetailsTable.setDefaultRenderer(Village.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(Integer.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(String.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(Tribe.class, coloredRenderer); for (int i = 0; i < jTargetDetailsTable.getColumnCount(); i++) { jTargetDetailsTable.getColumn(jTargetDetailsTable.getColumnName(i)).setHeaderRenderer(headerRenderer); } jTargetDetailsTable.revalidate(); //</editor-fold> }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createDeelnemersPanel() { JPanel panel = new JPanel(false); panel.setBackground(Color.BLACK); //panel.setLayout(new GridLayout(1, 0)); panel.setLayout(new BorderLayout()); JPanel innerPanel = new JPanel(); JLabel lbAanwezig = new JLabel("Deelnemers: "); innerPanel.add(lbAanwezig, BorderLayout.NORTH); tfAanwezig = new JLabel(Integer.toString(status.deelnemers.aantalAanwezig()), 10); innerPanel.add(tfAanwezig, BorderLayout.NORTH); //innerPanel.setLayout(new GridLayout(1, 0)); innerPanel.add(new JLabel("Naam:"), BorderLayout.NORTH); JTextField deelnemer = new JTextField(15); ArrayList<String> words = new ArrayList<>(); if (status.OSBOSpelers != null) { for (Speler s : status.OSBOSpelers.values()) { words.add(s.getNaam().trim()); words.add(Integer.toString(s.getKnsbnummer())); }//from ww w . j a v a 2s. c om } @SuppressWarnings("unused") Suggesties suggesties = new Suggesties(deelnemer, this, words, 2); innerPanel.add(deelnemer, BorderLayout.NORTH); deelnemer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); JButton btVoegToe = new JButton("Voeg toe"); btVoegToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); innerPanel.add(btVoegToe); panel.add(innerPanel); // panel_deelnemers.add(new JLabel("Deelnemers IJSCO toernooi")); deelnemersModel = new DeelnemersModel(panel, status.deelnemers); JTable deelnemersTabel = new JTable(deelnemersModel) { private static final long serialVersionUID = -8293073016982337108L; @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); DeelnemersModel model = (DeelnemersModel) getModel(); // Tooltip if (c instanceof JComponent) { ((JComponent) c) .setToolTipText(model.getToolTip(convertRowIndexToModel(row), column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } // Highlight overruled entries if (status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam() || status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam()) { c.setForeground(Color.BLUE); } else { c.setForeground(Color.BLACK); } return c; } }; deelnemersTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { status.groepen = null; status.schemas = null; status.schema = null; groepenText.setText(""); schemaModel.setSchemas(null); schemaModel.fireTableDataChanged(); if (status.deelnemers != null && tfAanwezig != null) { tfAanwezig.setText(Integer.toString(status.deelnemers.aantalAanwezig())); } panel.repaint(); } }); deelnemersTabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { logger.log(Level.INFO, "MouseEvent on table fired, type : " + e.toString()); logger.log(Level.INFO, "Popup trigger? : " + e.isPopupTrigger()); if (e.isPopupTrigger()) { int row = deelnemersTabel.rowAtPoint(e.getPoint()); JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Bewerk speler"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Bewerk Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); BewerkSpelerDialoog rd = new BewerkSpelerDialoog(new JFrame(), "Bewerk Speler", s, deelnemersModel); rd.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { System.out.println("closing..."); } }); rd.setVisible(true); } }); popup.add(menuItem); menuItem = new JMenuItem("Verwijder Speler"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Verwijder Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); status.deelnemers.remove(s); deelnemersModel.fireTableDataChanged(); } }); popup.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(deelnemersTabel); innerPanel.add(scrollPane, BorderLayout.CENTER); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(deelnemersModel); deelnemersTabel.setRowSorter(sorter); innerPanel.add(new JLabel("Filter op : ")); JTextField tfFilter = new JTextField(10); tfFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(tfFilter); JButton btPasToe = new JButton("Apply"); btPasToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(btPasToe); JButton btWis = new JButton("Wis"); btWis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { tfFilter.setText(""); logger.log(Level.INFO, "Wis filter"); sorter.setRowFilter(null); } }); innerPanel.add(btWis); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(0), 30); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(1), 55); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(2), 170); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(3), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(4), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(5), 30); Utils.fixedComponentSize(scrollPane, 400, 580); return panel; }
From source file:op.care.sysfiles.PnlFiles.java
void reloadTable() { HashSet<SYSFiles> filesSet = new HashSet<>(); EntityManager em = OPDE.createEM();/*from w w w . j a v a2s.com*/ Query query0 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.residentAssignCollection res WHERE res.resident = :resident"); query0.setParameter("resident", resident); filesSet.addAll(query0.getResultList()); Query query1 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.nrAssignCollection nr WHERE nr.nReport.resident = :resident"); query1.setParameter("resident", resident); filesSet.addAll(query1.getResultList()); Query query2 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.bwiAssignCollection bwi WHERE bwi.bwinfo.resident = :resident"); query2.setParameter("resident", resident); filesSet.addAll(query2.getResultList()); Query query3 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.preAssignCollection pre WHERE pre.prescription.resident = :resident"); query3.setParameter("resident", resident); filesSet.addAll(query3.getResultList()); Query query4 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.valAssignCollection val WHERE val.value.resident = :resident"); query4.setParameter("resident", resident); filesSet.addAll(query4.getResultList()); Query query5 = em.createQuery( "SELECT s FROM SYSFiles s JOIN s.npAssignCollection np WHERE np.nursingProcess.resident = :resident"); query5.setParameter("resident", resident); filesSet.addAll(query5.getResultList()); em.close(); ArrayList<SYSFiles> listFiles = new ArrayList<>(filesSet); Collections.sort(listFiles); // createFilters(); tmSYSFiles = new TMSYSFiles(listFiles); tblFiles.setModel(tmSYSFiles); sorter = new TableRowSorter(tmSYSFiles); sorter.setSortsOnUpdates(true); tblFiles.setRowSorter(sorter); // sorter.setComparator(TMSYSFiles.COL_PIT, new Comparator<Date>() { // @Override // public int compare(Date o1, Date o2) { // return o1.compareTo(o2); // } // }); // sorter.setRowFilter(textFilter); tblFiles.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd.MM.yyyy HH:mm"); return super.getTableCellRendererComponent(table, sdf.format((Date) value), isSelected, hasFocus, row, column); } }); tblFiles.getColumnModel().getColumn(1).setCellRenderer(new RNDHTML()); tblFiles.getColumnModel().getColumn(2).setCellRenderer(new RNDHTML()); tblFiles.getColumnModel().getColumn(3).setCellRenderer(new RNDHTML()); tblFiles.getColumnModel().getColumn(0).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader1")); tblFiles.getColumnModel().getColumn(1).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader2")); tblFiles.getColumnModel().getColumn(2).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader3")); tblFiles.getColumnModel().getColumn(3).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader4")); jspFiles.dispatchEvent(new ComponentEvent(jspFiles, ComponentEvent.COMPONENT_RESIZED)); }