Example usage for javax.swing.table TableRowSorter TableRowSorter

List of usage examples for javax.swing.table TableRowSorter TableRowSorter

Introduction

In this page you can find the example usage for javax.swing.table TableRowSorter TableRowSorter.

Prototype

public TableRowSorter(M model) 

Source Link

Document

Creates a TableRowSorter using model as the underlying TableModel.

Usage

From source file:com.sciaps.view.SpectrumShotPanel.java

/**
 * List Creates new form LibzListPanel//from w ww .ja v  a2s .  c om
 *
 * @param callback
 */
public SpectrumShotPanel(RegionFinderIntf callback) {
    initComponents();

    callback_ = callback;
    baselineSettingPanel_ = new BaselineRemovalSettingsPanel();
    shotListTableModel_ = new ShotListTableModel(callback);
    tblShots_.setModel(shotListTableModel_);
    tblShots_.getTableHeader().setReorderingAllowed(false);

    tblShots_.getColumnModel().getColumn(0).setPreferredWidth(45);
    tblShots_.getColumnModel().getColumn(0).setMinWidth(45);
    tblShots_.getColumnModel().getColumn(0).setMaxWidth(45);
    tblShots_.getColumnModel().getColumn(0).setResizable(false);

    sorter_ = new TableRowSorter<ShotListTableModel>(shotListTableModel_);
    tblShots_.setRowSorter(sorter_);
    txtFilterText_.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            filterTable();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            filterTable();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            filterTable();
        }
    });
}

From source file:com.tiempometa.muestradatos.JProgramTags.java

public JProgramTags(Frame owner, boolean modal) {
    super(owner, modal);
    initComponents();// w  w w.  j a v a2  s .co m
    logger.debug("Adding self to tag read listeners");
    ReaderContext.addReadingListener(this);
    tagReadTable.setModel(tagTableModel);
    tagReadTable.setAutoCreateRowSorter(true);
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(tagReadTable.getModel());
    sorter.setComparator(0, new BibComparator());
    tagReadTable.setRowSorter(sorter);
    List<Rfid> rfidList;
    try {
        rfidList = rfidDao.findAll();
        for (Rfid rfid : rfidList) {
            totalRfidMap.put(rfid.getRfid().toUpperCase(), rfid);
        }
        JOptionPane.showMessageDialog(this, "Se cargaron " + rfidList.size() + " tags de la base de datos",
                "Cantidad de tags disponibles", JOptionPane.INFORMATION_MESSAGE);
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(this,
                "No se pudo cargar la lista de tags a programar.\n" + e.getMessage(), "Error de base de datos",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:Visuals.PieChart.java

public JPanel addCharts() {
    ChartPanel piePanel = drawPieChart();
    piePanel.setDomainZoomable(true);/*  w w w .  j  a v  a  2  s.  c  o m*/
    JPanel thisPiePanel = new JPanel();

    String[][] finalRisks = new String[riskCount][4];
    for (int i = 0; i < riskCount; i++) {
        finalRisks[i][0] = risks[i][0];
        finalRisks[i][1] = risks[i][1];
        finalRisks[i][2] = risks[i][2];
        finalRisks[i][3] = risks[i][3];
    }

    JTable table = new JTable(finalRisks, columns);
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
    table.setRowSorter(sorter);
    List<RowSorter.SortKey> sortKeys = new ArrayList<>();

    int columnIndexToSort = 2;
    sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING));

    sorter.setSortKeys(sortKeys);
    sorter.sort();

    TableColumn tcol = table.getColumnModel().getColumn(2);
    table.removeColumn(tcol);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    table.getColumnModel().getColumn(1).setPreferredWidth(600);

    table.getColumnModel().getColumn(2).setPreferredWidth(600);

    JLabel right = new JLabel(
            "                                                                                                    ");
    thisPiePanel.add(right, BorderLayout.EAST);

    table.setShowHorizontalLines(true);
    table.setRowHeight(40);

    JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    Dimension d = table.getPreferredSize();
    tableScrollPane
            .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1)));
    table.setEnabled(false);
    thisPiePanel.setLayout(new BorderLayout());
    if (riskCount == 0) {

        thisPiePanel.add(piePanel, BorderLayout.CENTER);
    } else {
        thisPiePanel.add(right, BorderLayout.EAST);
        thisPiePanel.add(piePanel, BorderLayout.CENTER);
        thisPiePanel.add(tableScrollPane, BorderLayout.SOUTH);
    }
    thisPiePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    return thisPiePanel;
}

From source file:app.NewJFrame.java

private void showTable(List<WordStatistic> was) {
    TableModel model = new WordStatisticTableModel(was);
    jTable1.setModel(model);/*from   w  ww .  jav a2s.  c  om*/
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    jTable1.setRowSorter(sorter);
    was.sort(null);
}

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java

private void initComponents() {
    ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel();
    jtExtensions = new JKseTable(extensionsTableModel);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel);
    sorter.setComparator(2, new ObjectIdComparator());
    jtExtensions.setRowSorter(sorter);//from  w  w w  .ja v  a  2 s.  co m

    jtExtensions.setShowGrid(false);
    jtExtensions.setRowMargin(0);
    jtExtensions.getColumnModel().setColumnMargin(0);
    jtExtensions.getTableHeader().setReorderingAllowed(false);
    jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight()));

    for (int i = 0; i < jtExtensions.getColumnCount(); i++) {
        TableColumn column = jtExtensions.getColumnModel().getColumn(i);
        column.setHeaderRenderer(
                new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new ExtensionsTableCellRend());
    }

    TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0);
    criticalCol.setResizable(false);
    criticalCol.setMinWidth(28);
    criticalCol.setMaxWidth(28);
    criticalCol.setPreferredWidth(28);

    ListSelectionModel selectionModel = jtExtensions.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                try {
                    CursorUtil.setCursorBusy(DViewExtensions.this);
                    updateExtensionValue();
                } finally {
                    CursorUtil.setCursorFree(DViewExtensions.this);
                }
            }
        }
    });

    jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground());

    jpExtensionsTable = new JPanel(new BorderLayout(5, 5));
    jpExtensionsTable.setPreferredSize(new Dimension(500, 200));
    jpExtensionsTable.add(jspExtensionsTable, BorderLayout.CENTER);

    jpExtensionValue = new JPanel(new BorderLayout(5, 5));

    jlExtensionValue = new JLabel(res.getString("DViewExtensions.jlExtensionValue.text"));

    jpExtensionValue.add(jlExtensionValue, BorderLayout.NORTH);

    jepExtensionValue = new JEditorPane();
    jepExtensionValue.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize()));
    jepExtensionValue.setEditable(false);
    jepExtensionValue.setToolTipText(res.getString("DViewExtensions.jtaExtensionValue.tooltip"));
    // JGoodies - keep uneditable color same as editable
    jepExtensionValue.putClientProperty("JTextArea.infoBackground", Boolean.TRUE);

    // for displaying URLs in extensions as clickable links
    jepExtensionValue.setContentType("text/html");
    jepExtensionValue.addHyperlinkListener(this);
    // use default font and foreground color from the component
    jepExtensionValue.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    jspExtensionValue = PlatformUtil.createScrollPane(jepExtensionValue,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    jpExtensionValueTextArea = new JPanel(new BorderLayout(5, 5));
    jpExtensionValueTextArea.setPreferredSize(new Dimension(500, 200));
    jpExtensionValueTextArea.add(jspExtensionValue, BorderLayout.CENTER);

    jpExtensionValue.add(jpExtensionValueTextArea, BorderLayout.CENTER);

    jbAsn1 = new JButton(res.getString("DViewExtensions.jbAsn1.text"));

    PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewExtensions.jbAsn1.mnemonic").charAt(0));
    jbAsn1.setToolTipText(res.getString("DViewExtensions.jbAsn1.tooltip"));
    jbAsn1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewExtensions.this);
                asn1DumpPressed();
            } finally {
                CursorUtil.setCursorFree(DViewExtensions.this);
            }
        }
    });

    jpExtensionValueAsn1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    jpExtensionValueAsn1.add(jbAsn1);

    jpExtensionValue.add(jpExtensionValueAsn1, BorderLayout.SOUTH);

    jpExtensions = new JPanel(new GridLayout(2, 1, 5, 5));
    jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5),
            new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));

    jpExtensions.add(jpExtensionsTable);
    jpExtensions.add(jpExtensionValue);

    jbOK = new JButton(res.getString("DViewExtensions.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });

    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);

    extensionsTableModel.load(extensions);

    if (extensionsTableModel.getRowCount() > 0) {
        jtExtensions.changeSelection(0, 0, false, false);
    }

    getContentPane().add(jpExtensions, BorderLayout.CENTER);
    getContentPane().add(jpOK, BorderLayout.SOUTH);

    setResizable(false);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    getRootPane().setDefaultButton(jbOK);

    pack();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            jbOK.requestFocus();
        }
    });
}

From source file:Visuals.BarChart.java

public JPanel addCharts() {
    ChartPanel barPanel = drawBarChart();
    barPanel.setDomainZoomable(true);/* w  w  w.  ja v  a2  s  . co  m*/
    JPanel thisBarPanel = new JPanel();
    thisBarPanel.setLayout(new BorderLayout());

    String[][] finalRisks = new String[riskCount][4];
    for (int i = 0; i < riskCount; i++) {
        finalRisks[i][0] = risks[i][0];
        finalRisks[i][1] = risks[i][1];
        finalRisks[i][2] = risks[i][2];
        finalRisks[i][3] = risks[i][3];
    }

    JTable table = new JTable(finalRisks, columns);
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
    table.setRowSorter(sorter);
    List<RowSorter.SortKey> sortKeys = new ArrayList<>();

    int columnIndexToSort = 2;
    sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING));

    sorter.setSortKeys(sortKeys);
    sorter.sort();

    TableColumn tcol = table.getColumnModel().getColumn(2);
    table.removeColumn(tcol);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    table.getColumnModel().getColumn(1).setPreferredWidth(600);
    table.getColumnModel().getColumn(2).setPreferredWidth(600);

    table.setShowHorizontalLines(true);
    table.setRowHeight(40);
    table.setEnabled(false);

    JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    Dimension d = table.getPreferredSize();
    tableScrollPane
            .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1)));

    JLabel right = new JLabel(
            "                                                                                                    ");
    thisBarPanel.add(right, BorderLayout.EAST);
    thisBarPanel.add(barPanel, BorderLayout.CENTER);
    thisBarPanel.add(tableScrollPane, BorderLayout.SOUTH);
    return thisBarPanel;
}

From source file:edu.harvard.mcz.imagecapture.SpecimenBrowser.java

/**
 * This method initializes jTable   //from w  w  w  .  j  a  va 2  s .c o m
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTable == null) {
        jTable = new JTable();
        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        //jTable.setAutoCreateRowSorter(true);
        SpecimenLifeCycle s = new SpecimenLifeCycle();
        SpecimenListTableModel model = null;
        if (searchCriteria == null) {
            model = new SpecimenListTableModel(s.findAll());
        } else {
            if (useLike) {
                model = new SpecimenListTableModel(s.findByExampleLike(searchCriteria));
            } else {
                model = new SpecimenListTableModel(s.findByExample(searchCriteria));
            }
        }
        jTable.setModel(model);
        sorter = new TableRowSorter<SpecimenListTableModel>(model);
        jTable.setRowSorter(sorter);
        //jTable.setDefaultRenderer(Long.class, new ButtonRenderer());
        //jTable.setDefaultEditor(Long.class, new ButtonEditor());
        jTable.setDefaultRenderer(Specimen.class, new ButtonRenderer());
        jTable.setDefaultEditor(Specimen.class, new ButtonEditor());
        // set some column widths
        int characterWidth = Singleton.getSingletonInstance().getCharacterWidth();
        jTable.getColumnModel().getColumn(0).setPreferredWidth(characterWidth * 5);
        jTable.getColumnModel().getColumn(1).setPreferredWidth(characterWidth * 14);
    }
    return jTable;
}

From source file:edu.harvard.mcz.imagecapture.encoder.UnitTrayLabelBrowser.java

/**
 * This method initializes jTable   /*ww w.  ja  va 2  s  .com*/
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTable == null) {
        tableModel = new UnitTrayLabelTableModel();
        jTable = new DragDropJTable(tableModel);
        jTable.setDragEnabled(true);
        jTable.setDropMode(DropMode.ON);
        //tableModel.addUndoableEditListener(new MyUndoableEditListener());
        sorter = new TableRowSorter<UnitTrayLabelTableModel>(tableModel);
        jTable.setRowSorter(sorter);
    }
    return jTable;
}

From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java

private void initComponents() {
    dateField = new DatePanel();
    closeField = new JFloatField();
    lowField = new JFloatField();
    highField = new JFloatField();
    securityCombo = new SecurityComboBox();
    volumeField = new JIntegerField();

    updateButton = new JButton(rb.getString("Button.UpdateOnline"),
            IconUtils.getIcon("/jgnash/resource/applications-internet.png"));

    deleteButton = new JButton(rb.getString("Button.Delete"));
    clearButton = new JButton(rb.getString("Button.Clear"));
    applyButton = new JButton(rb.getString("Button.Add"));
    closeButton = new JButton(rb.getString("Button.Close"));

    model = new HistoryModel();

    table = new HistoryTable();
    table.setModel(model);/*from  w w  w .ja v a  2s  . com*/
    table.setPreferredScrollableViewportSize(new Dimension(150, 120));
    table.setCellSelectionEnabled(false);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setRowSorter(new TableRowSorter<>(model));
    table.setFillsViewportHeight(true);

    // create an empty chart for panel construction
    chartPanel = new ChartPanel(new JFreeChart(new XYPlot()));
    chartPanel.setPreferredSize(new Dimension(150, 90));

    applyButton.addActionListener(this);
    clearButton.addActionListener(this);
    deleteButton.addActionListener(this);
    updateButton.addActionListener(this);
    securityCombo.addActionListener(this);
    closeButton.addActionListener(this);
}

From source file:view.ResultsPanel.java

public void setTable(int nbMode, List<ElementaryMode> modes) {

    ElementaryMode mode = modes.get(nbMode);

    DefaultTableModel model = (DefaultTableModel) modeTable.getModel();

    while (model.getRowCount() > 0) {
        model.removeRow(0);/* w  ww  .  ja  va2  s  . c  om*/
    }

    Map<Reaction, Double> map = mode.getContent();
    for (Reaction key : map.keySet()) {

        model.addRow(new Object[] { map.get(key), key.getName(), key.getStringReaction() });

    }

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modeTable.getModel());
    modeTable.setRowSorter(sorter);
    modeTable.getTableHeader().setReorderingAllowed(false);

    searchField.getDocument().addDocumentListener(new MyDocumentListener(searchField, sorter, 1, 2));

    searchField.setText(searchField.getText());

}