Filter JTable only one column

I have a JTable, and I would like to make a filter from JTextfield , but only filter the results based on a single column, and not search all columns.

I have a JTable that I can filter, but my filter will filter and search for each column of the table, I want to limit it to one column

Can this be done?

+7
source share
3 answers

Listen to the changes to the textFields document and set the corresponding 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 protection against an empty text field)

+12
source

Keep the main copy of all rows (or supporting data) in the background.

When searching, find the search criteria from the text box and rebuild the table model by adding only those elements that match the criteria. If the text box is empty, add all lines.

+1
source

You can expand the envelope table model as follows http://java-sl.com/envelope.html and leave only the necessary lines.

+1
source

All Articles