Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:39:43+00:00 2026-05-24T16:39:43+00:00

I have a JTable (DefaultTableModel) and a JTextField. I’d like to filter the JTable

  • 0

I have a JTable (DefaultTableModel) and a JTextField. I’d like to filter the JTable with the regex I put into the text field. When I start the program, all entries are shown, but when I enter text into the text field, no rows are displayed even though it should find the text within a row.

private void createFilter() {
    _sorter = new TableRowSorter<DefaultTableModel>(new DefaultTableModel());

    JPanel filterPanel = new JPanel();
    filterPanel.setLayout(new BorderLayout());

    JLabel filterLabel = new JLabel("Filter:");
    filterPanel.add(filterLabel, BorderLayout.WEST);

    _inputField = new JTextField();
    _inputField.setColumns(40);
    filterPanel.add(_inputField, BorderLayout.CENTER);
    _inputField.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent de) {
            newFilter();
        }

        public void removeUpdate(DocumentEvent de) {
            newFilter();
        }

        public void changedUpdate(DocumentEvent de) {
            newFilter();
        }
    });

    JButton clearButton = new JButton("X");
    clearButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            _inputField.setText("");
        }
    });
    filterPanel.add(clearButton, BorderLayout.EAST);

    _mainFrame.add(filterPanel, BorderLayout.SOUTH);
}

private void newFilter() {
    RowFilter<DefaultTableModel, Object> rowFilter = null;
    try {
        rowFilter = RowFilter.regexFilter(_inputField.getText());
    }
    catch(java.util.regex.PatternSyntaxException ex) {
        return;
    }
    _sorter.setRowFilter(rowFilter);
    _table.setRowSorter(_sorter);
}

My debugger shows me, that rowFilter is initialized, so it can’t be because of a wrong RegEx. Also newFilter() is called at every keystroke.

Thanks in advance. I’d be happy to provide more information if needed.

Sincerely,
Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:39:45+00:00Added an answer on May 24, 2026 at 4:39 pm

    It seems that the JTable and the TableRowSorter each have a different table model. The TableRowSorter should be constructed with the table model of the JTable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable displays the event accordingly, I want to do like when
I have a JTable using a custom DefaultTableModel which has some Booleans in the
I have problems on inserting rows into a JTable and I don't know what
I have a JTable and a TableRowSorter which I'd like to perform an operation
I have a JTable to which I linked a DefaultTableModel and a TableRowSorter .
I am currently building a database using JTable and DefaultTableModel. In my program I
I have a GUI with a JTable using the DefaultTableModel. These instance variables are
I have a JTable with a custom TableModel called DataTableModel . I initialized the
I have a JTable that is within a JScrollPane. Rows are added to the
I have a JTable inside of a JScrollPane . I am creating a custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.