I have a standard JTable with certain data inside. I would like to create an automatic filtering function: as the user types in a specific textfield the words the filtering process is started automatically, without the need of a clicking a button. Is it possible in Java Swing?
Share
Yes, it is possible!
Start the SwingSet3 Demo (from Swinglabs): http://download.java.net/javadesktop/swingset3/SwingSet3.jnlp
In the Data category there is a JTable demo listing Oscar candidates and winners.
The TextField with the title “Search Titles and Recipients” is exactly doing what you want.
The SwingSet3 Demo even lets you highlight the code snippets via the ComboBox-entry “Setup search filter”.
The RowFilter in the first snippet ignores leading “The “s and “A “s to match more movie titles. I would replace the RegEx pattern with this
to get a real “find everything while I type” user experience.
The second snippet shows you how to implement a
DocumentListenerto refresh the table filter on every keystroke.