Search in sources :

Example 1 with TableRowSorter

use of javax.swing.table.TableRowSorter in project gitblit by gitblit.

the class GitblitAuthority method filterUsers.

private void filterUsers(final String fragment) {
    table.clearSelection();
    userCertificatePanel.setUserCertificateModel(null);
    if (StringUtils.isEmpty(fragment)) {
        table.setRowSorter(defaultSorter);
        return;
    }
    RowFilter<UserCertificateTableModel, Object> containsFilter = new RowFilter<UserCertificateTableModel, Object>() {

        @Override
        public boolean include(Entry<? extends UserCertificateTableModel, ? extends Object> entry) {
            for (int i = entry.getValueCount() - 1; i >= 0; i--) {
                if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) {
                    return true;
                }
            }
            return false;
        }
    };
    TableRowSorter<UserCertificateTableModel> sorter = new TableRowSorter<UserCertificateTableModel>(tableModel);
    sorter.setRowFilter(containsFilter);
    table.setRowSorter(sorter);
}
Also used : RowFilter(javax.swing.RowFilter) Point(java.awt.Point) TableRowSorter(javax.swing.table.TableRowSorter)

Example 2 with TableRowSorter

use of javax.swing.table.TableRowSorter in project binnavi by google.

the class ComplexTypePanel method createControls.

private void createControls(final List<BaseType> baseTypes) {
    setBorder(new EmptyBorder(5, 5, 5, 5));
    final GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 0, 0 };
    gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE };
    setLayout(gridBagLayout);
    final JLabel lblName = new JLabel("Name:");
    GridBagConstraints gbcLblName = new GridBagConstraints();
    gbcLblName.insets = new Insets(0, 0, 5, 5);
    gbcLblName.anchor = GridBagConstraints.WEST;
    gbcLblName.gridx = 0;
    gbcLblName.gridy = 0;
    add(lblName, gbcLblName);
    name = new JTextField();
    GridBagConstraints gbcName = new GridBagConstraints();
    gbcName.insets = new Insets(0, 0, 5, 0);
    gbcName.fill = GridBagConstraints.HORIZONTAL;
    gbcName.gridx = 1;
    gbcName.gridy = 0;
    add(name, gbcName);
    name.setColumns(10);
    final JLabel lblMembers = new JLabel("Members:");
    final GridBagConstraints gbcLblMembers = new GridBagConstraints();
    gbcLblMembers.anchor = GridBagConstraints.WEST;
    gbcLblMembers.insets = new Insets(0, 0, 5, 5);
    gbcLblMembers.gridx = 0;
    gbcLblMembers.gridy = 2;
    add(lblMembers, gbcLblMembers);
    final MemberTableModel model = new MemberTableModel();
    model.addTableModelListener(new MemberTableModelListener());
    members = new MemberTable(model, baseTypes);
    final TableRowSorter<MemberTableModel> sorter = new TableRowSorter<MemberTableModel>(model);
    // Triggers immediate re-sort when offset is updated.
    sorter.setSortsOnUpdates(true);
    sorter.setSortable(MemberTableModel.NAME_COLUMN, false);
    sorter.setSortable(MemberTableModel.TYPE_COLUMN, false);
    // Initial state is ascending sort order.
    sorter.toggleSortOrder(MemberTableModel.INDEX_COLUMN);
    members.setRowSorter(sorter);
    final GridBagConstraints gbcMembers = new GridBagConstraints();
    gbcMembers.insets = new Insets(0, 0, 5, 0);
    gbcMembers.fill = GridBagConstraints.BOTH;
    gbcMembers.gridx = 1;
    gbcMembers.gridy = 2;
    add(new JScrollPane(members), gbcMembers);
    final JLabel lblPreview = new JLabel("Preview:");
    final GridBagConstraints gbcLblPreview = new GridBagConstraints();
    gbcLblPreview.anchor = GridBagConstraints.WEST;
    gbcLblPreview.insets = new Insets(0, 0, 0, 5);
    gbcLblPreview.gridx = 0;
    gbcLblPreview.gridy = 3;
    add(lblPreview, gbcLblPreview);
    final JTextArea preview = new JTextArea();
    final GridBagConstraints gbcPreview = new GridBagConstraints();
    gbcPreview.fill = GridBagConstraints.BOTH;
    gbcPreview.gridx = 1;
    gbcPreview.gridy = 3;
    add(preview, gbcPreview);
}
Also used : JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) EmptyBorder(javax.swing.border.EmptyBorder) TableRowSorter(javax.swing.table.TableRowSorter)

Example 3 with TableRowSorter

use of javax.swing.table.TableRowSorter in project jdk8u_jdk by JetBrains.

the class bug7055065 method createAndShowUI.

private static void createAndShowUI() {
    JFrame frame = new JFrame("SimpleTableDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel newContentPane = new JPanel();
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);
    final String[] columnNames = { "String", "Number" };
    final Object[][] data = { { "aaaa", new Integer(1) }, { "bbbb", new Integer(3) }, { "cccc", new Integer(2) }, { "dddd", new Integer(4) }, { "eeee", new Integer(5) } };
    table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 400));
    table.setFillsViewportHeight(true);
    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public Class<?> getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        public boolean isCellEditable(int row, int col) {
            return col != 5;
        }

        public void setValueAt(Object aValue, int row, int column) {
            data[row][column] = aValue;
        }
    };
    table.setModel(dataModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(dataModel);
    table.setRowSorter(sorter);
    JScrollPane scrollPane = new JScrollPane(table);
    newContentPane.add(scrollPane);
    frame.pack();
    frame.setLocation(0, 0);
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Dimension(java.awt.Dimension) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter)

Example 4 with TableRowSorter

use of javax.swing.table.TableRowSorter in project otapij by FellowTraveler.

the class MarketTradesTableModel method setValue.

public void setValue(Map values, JTable table) {
    clearValue();
    System.out.println("values.size():" + values.size());
    Set set = values.keySet();
    Iterator iterator = set.iterator();
    int i = 0;
    data = new Object[values.size()][];
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String[] row = (String[]) values.get(key);
        data[i] = row;
        i++;
    }
    if (values.size() > 0) {
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this);
        table.setRowSorter(sorter);
    }
    fireTableDataChanged();
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) TableRowSorter(javax.swing.table.TableRowSorter) DefaultTableModel(javax.swing.table.DefaultTableModel) TableModel(javax.swing.table.TableModel)

Example 5 with TableRowSorter

use of javax.swing.table.TableRowSorter in project otapij by FellowTraveler.

the class BitcoinReceivingAddrTableModel method setValue.

public void setValue(Map values, JTable receiveAddrTable) {
    clearValue();
    System.out.println("values.size():" + values.size());
    Set set = values.keySet();
    Iterator iterator = set.iterator();
    int i = 0;
    data = new Object[values.size()][];
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String[] row = (String[]) values.get(key);
        data[i] = row;
        i++;
    }
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this);
    receiveAddrTable.setRowSorter(sorter);
    /*TableColumnModel tcm = receiveAddrTable.getColumnModel();
      System.out.println("receivedTable.getColumn()"+tcm.getColumnCount());
      if(tcm.getColumnCount()==6){
        receiveAddrTable.removeColumn(tcm.getColumn(5));
      }*/
    fireTableDataChanged();
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) TableRowSorter(javax.swing.table.TableRowSorter) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

TableRowSorter (javax.swing.table.TableRowSorter)32 JTable (javax.swing.JTable)23 JScrollPane (javax.swing.JScrollPane)22 JPanel (javax.swing.JPanel)17 JLabel (javax.swing.JLabel)15 BoxLayout (javax.swing.BoxLayout)13 JButton (javax.swing.JButton)13 TableColumnModel (javax.swing.table.TableColumnModel)10 Dimension (java.awt.Dimension)9 ActionEvent (java.awt.event.ActionEvent)9 SystemNameComparator (jmri.util.SystemNameComparator)9 ActionListener (java.awt.event.ActionListener)8 TableColumn (javax.swing.table.TableColumn)8 TableModel (javax.swing.table.TableModel)7 ButtonEditor (jmri.util.table.ButtonEditor)6 ButtonRenderer (jmri.util.table.ButtonRenderer)6 BorderLayout (java.awt.BorderLayout)5 FlowLayout (java.awt.FlowLayout)5 Point (java.awt.Point)5 JComboBox (javax.swing.JComboBox)5