Filter JTable only one one column
-
I have a JTable and I would like to do a filter from a JTextfield but only filter the results based on one column and not to search all columns. I have my JTable I can filter but my filter will filter and search every column of the table I want to restrict it to one column Can it be done ?
-
Answer:
listen to changes in the textFields document and set the appropriate rowFilter limited to the column you want to filter: // on document change RowFilter rowFilter = RowFilter.regexFilter(textField.getText(), myColumn); table.getRowSorter().setRowFilter(rowFilter); (type-cast and guard against empty textfield ommitted)
CMP at Stack Overflow Visit the source
Other answers
Keep a master copy of all the rows (or supporting data) in the background. When searching, take the search criteria from the text field and rebuild the table model by only adding items that match the criteria. If the text field is empty then add all rows.
jzd
You can extend envelope table model like this http://java-sl.com/envelope.html and leave only necessary rows.
StanislavL
Related Q & A:
- How to add data to the Jtable?Best solution by Stack Overflow
- How to split column text to another column?Best solution by Stack Overflow
- How to use jTable in java?Best solution by Yahoo! Answers
- How to find the column name of the first column with a null value?Best solution by Stack Overflow
- How to change column data's as a separate column wise format in a SQL Server?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.