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 8684989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:26:46+00:00 2026-06-12T22:26:46+00:00

I have a 12 filters for 12 columns on a JTable. Each filter is

  • 0

I have a 12 filters for 12 columns on a JTable. Each filter is a TextField of type JTextField. Every time a user enters the data in the text box filter then search happens.

Example:
Suppose say, I have 3 columns and 3 text boxes above them as filters. Now any thing which is typed in any of the text boxes my table filtering has to happen. It is happening great.

╔═════════════╦═════════════╦═════════════╗
║ [TextField] ║ [TextField] ║ [TextField] ║
╠═════════════╬═════════════╬═════════════╣
║             ║             ║             ║
╠═════════════╬═════════════╬═════════════╣
      ...           ...           ...
╠═════════════╬═════════════╬═════════════╣
║             ║             ║             ║
╚═════════════╩═════════════╩═════════════╝

Text field listener for each of the text field looks like this,

textField.getDocument().addDocumentListener(new DocumentListener() {
  public void changedUpdate(DocumentEvent e) { method(); } 
  public void removeUpdate(DocumentEvent e) { method(); }
  public void insertUpdate(DocumentEvent e) { method(); } 
};

My question is, I am repeating this code for all the 12 text fields, which I was not really happy. Is this the only way we have ? or can some one suggest me a better way ?

  • 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-06-12T22:26:47+00:00Added an answer on June 12, 2026 at 10:26 pm
    • Switch from an anonymous class to an inner class and attach the same listener to each field. The source is contained in the event
    • Make it a separate class and keep on using separate listeners for each field. Avoids at least the code duplication

    See this tutorial for an example of an inner class

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

Sidebar

Related Questions

i have added filter to each of the columns in a grid panel. When
How do I filter by columns with PDO? I have the following: $sth =
How to filter DataView/DataTable by time? I have a table with datetime column inside
I have multiple filters in my application, with one at the root. <filter> <filter-name>root</filter-name>
I have a hibernate filter that needs to evaluate using two different columns in
I have a sheet with user details in columns A - C. Columns D-H
Let's say I have a large set of data within which each datum has
I have a JTable with four columns, the first one containing either a number
I have a JTable and I would like to do a filter from a
In a datasheet with automatic filters, I have this (values and columns names are

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.