javax.swing.RowFilter类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中javax.swing.RowFilter类的一些代码示例,展示了RowFilter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RowFilter类的具体详情如下:
包路径:javax.swing.RowFilter
类名称:RowFilter

RowFilter介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private JTable jTable = new JTable(model);
    = new TableRowSorter<>(jTable.getModel());
  jTable.setRowSorter(rowSorter);
  panel.add(new JLabel("Specify a word to match:"),
      BorderLayout.WEST);
  panel.add(jtfFilter, BorderLayout.CENTER);
  setLayout(new BorderLayout());
  add(panel, BorderLayout.SOUTH);
  add(new JScrollPane(jTable), BorderLayout.CENTER);
        rowSorter.setRowFilter(null);
      } else {
        rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
        rowSorter.setRowFilter(null);
      } else {
        rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));

代码示例来源:origin: magefree/mage

stateFilterList.add(RowFilter.regexFilter("Waiting", TablesTableModel.COLUMN_STATUS));
stateFilterList.add(RowFilter.regexFilter("Dueling|Constructing|Drafting|Sideboard", TablesTableModel.COLUMN_STATUS));
typeFilterList.add(RowFilter.regexFilter("Two|Commander|Free|Tiny|Momir", TablesTableModel.COLUMN_GAME_TYPE));
typeFilterList.add(RowFilter.regexFilter("Constructed", TablesTableModel.COLUMN_GAME_TYPE));
typeFilterList.add(RowFilter.regexFilter("Booster|Sealed", TablesTableModel.COLUMN_GAME_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed.*Block", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Standard", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Modern", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Legacy", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Constructed - Vintage", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Commander|^Duel Commander|^Penny Dreadful Commander|^Freeform Commander|^MTGO 1v1 Commander|^Duel Brawl|^Brawl", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Tiny", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Limited", TablesTableModel.COLUMN_DECK_TYPE));
formatFilterList.add(RowFilter.regexFilter("^Momir Basic|^Constructed - Pauper|^Constructed - Frontier|^Constructed - Extended|^Constructed - Eternal|^Constructed - Historical|^Constructed - Super|^Constructed - Freeform|^Australian Highlander|^Canadian Highlander|^Constructed - Old", TablesTableModel.COLUMN_DECK_TYPE));
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.BEGINNER, true), TablesTableModel.COLUMN_SKILL));

代码示例来源:origin: stackoverflow.com

filterCpText.setBackground(Color.LIGHT_GRAY);
JPanel filterCpPanel = new JPanel();
filterCpPanel.setLayout(new BorderLayout(5, 5));
filterCpPanel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
filterCpPanel.setBackground(Color.LIGHT_GRAY);
filterCpPanel.setPreferredSize(new Dimension(300, 30));
filterCpPanel.add(filterCpText, BorderLayout.CENTER);
add(filterCpPanel, BorderLayout.NORTH);
final JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 160));
table.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
TableModel myTableModel = table.getModel();
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(myTableModel);
table.setRowSorter(sorter);
filterCpText.getDocument().addDocumentListener(new DocumentListener() {
    String text = filterCpText.getText();
    if (text.length() == 0) {
      sorter.setRowFilter(null);
      table.clearSelection();
    } else {
      try {
        sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text, 4));
        table.clearSelection();
      } catch (PatternSyntaxException pse) {

代码示例来源:origin: stackoverflow.com

initTableModel();
rowSorter = new TableRowSorter<DefaultTableModel>(searchTableModel);
searchTable = new JTable(searchTableModel);
searchTable.setRowSorter(rowSorter);
searchTable.setFillsViewportHeight(true);
searchTable.getColumnModel().setColumnSelectionAllowed(false);
searchTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
popup.add(searchTable);
popup.setVisible(false);
popup.setBorder(BorderFactory.createEmptyBorder());
searchPanel.add(searchField, BorderLayout.CENTER);
frame.add(searchPanel, BorderLayout.NORTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 500);
  rf = RowFilter.regexFilter(getFilterText(), 0);
rowSorter.setRowFilter(rf);

代码示例来源:origin: stackoverflow.com

setLayout(new BorderLayout());
sorter = new TableRowSorter<MyTableModel>(model);
table = new JTable(model) {
  public String getToolTipText(MouseEvent e) {
    Point p = e.getPoint();
    int row = convertRowIndexToModel(rowAtPoint(p));
    MyTableModel model = (MyTableModel) table.getModel();
    return model.getPath(row);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(
  new JScrollPane(table), BorderLayout.CENTER);
add(filterText, BorderLayout.SOUTH);
  rf = RowFilter.regexFilter("(?i)" + filterText.getText());
} catch (java.util.regex.PatternSyntaxException e) {
  return;
sorter.setRowFilter(rf);

代码示例来源:origin: stackoverflow.com

try {
      filterText = document.getText(0, document.getLength()).trim();
      rowFilter = RowFilter.regexFilter("(?i)" + filterText);
    } catch (java.util.regex.PatternSyntaxException e) {
      return;
      return;
    rowSorter.setRowFilter(rowFilter);
    table.setRowSorter(rowSorter);
  popupWindow.getContentPane().add(getWindowComponent());
  popupWindow.setLocation(new Point(SearchBox.this.getLocationOnScreen().x, SearchBox.this.getLocationOnScreen().y + 25));
  popupWindow.setUndecorated(true);
add(editor);
add(arrowButton);
setBackground(editor.getBackground());
setBorder(editor.getBorder());
  rowSorter = new TableRowSorter<DefaultTableModel>(tableModel);
  table = new JTable(tableModel);
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  table.setAutoCreateRowSorter(true);

代码示例来源:origin: stackoverflow.com

table = new JTable(model);
table.setRowHeight(pHeight);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table.setRowSorter(sorter);
filterText.setMaximumSize(new Dimension(400, 30));
    String text = filterText.getText();
    if (text.length() == 0) {
      sorter.setRowFilter(null);
      table.clearSelection();
    } else {
      try {
        sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
      } catch (PatternSyntaxException pse) {
        JOptionPane.showMessageDialog(null, "Bad regex pattern", "Bad regex pattern", JOptionPane.ERROR_MESSAGE);
add(filterText, BorderLayout.NORTH);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
myLabel.setPreferredSize(new Dimension(200, pHeight));
myLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(myLabel, BorderLayout.SOUTH);
new Thread(this).start();

代码示例来源:origin: stackoverflow.com

JTable table = new JTable(tableData, header);
if (listLike) {
  Dimension d = table.getPreferredScrollableViewportSize();
  table.setPreferredScrollableViewportSize(new Dimension(d.width/2,d.height));
  table.setShowGrid(false);
  table.setTableHeader(null);
  table.setFillsViewportHeight(true);
ui.add(new JScrollPane(table));
sorter = new TableRowSorter(table.getModel());
table.setRowSorter(sorter);
ui.add(filterText, BorderLayout.PAGE_START);
Document doc = filterText.getDocument();
DocumentListener listener = new DocumentListener() {
  rf = RowFilter.regexFilter(filterText.getText(), 0);
} catch (java.util.regex.PatternSyntaxException e) {
  return;
sorter.setRowFilter(rf);
    f.setLocationByPlatform(true);
    f.add(o1.getUI(), BorderLayout.LINE_START);
    f.add(o2.getUI(), BorderLayout.CENTER);
    f.pack();

代码示例来源:origin: stackoverflow.com

frame.add(new TestPane());
  frame.pack();
  frame.setLocationRelativeTo(null);
setLayout(new BorderLayout());
JTable table = new JTable(model);
table.setAutoCreateRowSorter(true);
TableUtilities.installFilterSupport(table,
        new TableUtilities.IFilterListener() {
          @Override
          public void filterChanged(JTable table, String filter) {
            TableRowSorter sorter = (TableRowSorter) table.getRowSorter();
            if (filter == null || filter.trim().length() == 0) {
              filter = "*";
            sorter.setRowFilter(RowFilter.regexFilter(filter));
add(new JScrollPane(table));

代码示例来源:origin: stackoverflow.com

private final JTable table = new JTable(model);
private final TableRowSorter<TableModel> rowSorter = new TableRowSorter<>(model);
private final JTextField searchFilter = new JTextField();
private final JButton open = new JButton("open");
 table.setRowSorter(rowSorter);
 open.addActionListener(new OpenData());//end OpenData class
 panel.add(new JLabel("Search:"), BorderLayout.WEST);
 panel.add(searchFilter, BorderLayout.CENTER);
 panel.add(open, BorderLayout.EAST);
   System.out.println(text);
   if (text.trim().length() == 0) {
    rowSorter.setRowFilter(null);
   } else {
    rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
   String text = searchFilter.getText();
   if (text.trim().length() == 0) {
    rowSorter.setRowFilter(null);
   } else {
    rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
   m.addRow(dataArray);
  table.setModel(m);
  rowSorter.setModel(m);

代码示例来源:origin: stackoverflow.com

private JTable table = new JTable(model);
  table.setPreferredScrollableViewportSize(table.getPreferredSize());
  sorter = new TableRowSorter<TableModel>(model);
  table.setRowSorter(sorter);
  Date d1 = (Date) model.getValueAt(0, 3);
  Date d2 = (Date) model.getValueAt(model.getRowCount() - 2, 3);
  RowFilter<TableModel, Integer> low = RowFilter.dateFilter(RowFilter.ComparisonType.AFTER, d1, 3);
  RowFilter<TableModel, Integer> high = RowFilter.dateFilter(RowFilter.ComparisonType.BEFORE, d2, 3);
  List<RowFilter<TableModel, Integer>> filters = Arrays.asList(low, high);
  final RowFilter<TableModel, Integer> filter = RowFilter.andFilter(filters);
  JScrollPane scrollPane = new JScrollPane(table);
  JFrame frame = new JFrame("Filtering Table");
  frame.add(new JButton(new AbstractAction("Toggle filter") {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (sorter.getRowFilter() != null) {
        sorter.setRowFilter(null);
      } else {
        sorter.setRowFilter(filter);
  frame.add(scrollPane);
  frame.pack();
  frame.setLocationByPlatform(true);

代码示例来源:origin: net.sourceforge.javydreamercsw/Client-UI

if (getHeaderCheckbox().isSelected()) {
  TableRowSorter sorter
      = new TableRowSorter<>(tableModel);
  getImportTable().setRowSorter(sorter);
  RowFilter<DefaultTableModel, Object> rf;
        = RowFilter.regexFilter(MessageFormat.format("^{0}",
                tableModel.getValueAt(1, 0)));
    rf = RowFilter.notFilter(regexFilter);
    sorter.setRowFilter(rf);

代码示例来源:origin: ron190/jsql-injection

@Override
public void insertUpdate(DocumentEvent e) {
  String text = textFilter.getText();
  if (text.trim().length() == 0) {
    rowSorter.setRowFilter(null);
  } else {
    rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + Pattern.quote(text)));
  }
}

代码示例来源:origin: com.numdata/numdata-swing

final Cursor    topLevelCursor   = ( topLevelAncestor == null ) ? null : topLevelAncestor.getCursor();
final Cursor    fieldCursor      = field.getCursor();
final Cursor    waitCursor       = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
  topLevelAncestor.setCursor( waitCursor );
  if ( TextTools.isEmpty( text ) )
    sorter.setRowFilter( originalRowFilter );
      filters.add( RowFilter.regexFilter( "(?i)" + Pattern.quote( word ) ) );
    sorter.setRowFilter( RowFilter.andFilter( filters ) );
    topLevelAncestor.setCursor( topLevelCursor );

代码示例来源:origin: igniterealtime/Spark

@Override
  public void keyReleased(KeyEvent e) {
    JTextField textField = (JTextField)e.getSource();
    String text = textField.getText();
    List<RowFilter<Object,Object>> filters = new ArrayList<>();
    filters.add(RowFilter.regexFilter(text, 1));
    filters.add(RowFilter.regexFilter(text, 2));
    filters.add(RowFilter.regexFilter(text, 3));
    RowFilter<Object,Object> af = RowFilter.orFilter(filters);
    sorter.setRowFilter(af);
  }
});

代码示例来源:origin: MegaMek/megamek

private void filter() {
  List<RowFilter<UnitTableModel,Integer>> filters = new ArrayList<>();
  for (int i = 0; i < allConstraints.size(); i++) {
    if (otherCriteriaChecks.get(i).isSelected()) {
      filters.add(new UnitTableRowFilter(allConstraints.get(i)));
    }            
  }
  if (otherCriteriaChecks.size() > allConstraints.size()
      && otherCriteriaChecks.get(otherCriteriaChecks.size() - 1).isSelected()) {
    filters.add(new UnitTableRowFilter(formationType.getGroupingCriteria()));
  }
  tableSorter.setRowFilter(RowFilter.andFilter(filters));
}

代码示例来源:origin: stackoverflow.com

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javax.swing;

import java.text.Normalizer;

/**
 *
 * @author Miroslav
 */
public abstract class RowFilterSpecialFilter {

  public static <M, I> RowFilter<M, I> regexFilterAccentIndiferent(String regex) {
    return RowFilter.regexFilter("(?i)" + Normalizer.normalize(regex, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""));
  }

  public static <M, I> RowFilter<M, I> regexFilterAccentIndiferent(String regex, int... indices) {
    return RowFilter.regexFilter("(?i)" + Normalizer.normalize(regex, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""), indices);
  }
}

代码示例来源:origin: otros-systems/otroslogviewer

private RowFilter<VfsTableModel, Integer> createFilter() {
 RowFilter<VfsTableModel, Integer> regexFilter = new VfsTableModelFileNameRowFilter(filterField);
 RowFilter<VfsTableModel, Integer> hiddenFilter = new VfsTableModelHiddenFileRowFilter(showHidden);
 RowFilter<VfsTableModel, Integer> alwaysShowParent = new VfsTableModelShowParentRowFilter();
 @SuppressWarnings("unchecked") RowFilter<VfsTableModel, Integer> filters = RowFilter.andFilter(Arrays.asList(regexFilter, hiddenFilter));
 filters = RowFilter.orFilter(Arrays.asList(filters, alwaysShowParent));
 return filters;
}

代码示例来源:origin: eugener/oxbow

@Override
public boolean include( final RowFilter.Entry<? extends Object, ? extends Object> entry) {
  // use parent filter condition
  if ( parentFilter != null && !parentFilter.include(entry)) return false;
  return includeRow( new ITableFilter.Row() {
    @Override
    public Object getValue(int column) { return entry.getValue(column); }
    @Override
    public int getValueCount() { return entry.getValueCount(); }
  });
}

代码示例来源:origin: io.ultreia.java4all.i18n/i18n-editor

public void updateListFromUserFilter(String text) {
  RowFilter<ListModel, Integer> rowFilter = new RowFilter<ListModel, Integer>() {
    @Override
    public boolean include(Entry<? extends ListModel, ? extends Integer> entry) {
      if (text == null) {
        return true;
      }
      for (int i = entry.getValueCount() - 1; i >= 0; i--) {
        String itemKey = entry.getStringValue(i);
        Item item = get(itemKey);
        boolean match = itemKey.contains(text) || item.getItems().stream().anyMatch(e -> e.getLastValidValue().contains(text));
        if (match) {
          return true;
        }
      }
      return false;
    }
  };
  if (filter == null) {
    list.setRowFilter(rowFilter);
  } else {
    list.setRowFilter(RowFilter.andFilter(ImmutableList.of(filter, rowFilter)));
  }
  updateTabTitle();
  refreshActions();
}

相关文章