Reputation: 19
If I click on the combobox value then the JTable row with same value as the selected combobox should only get display.
For example:
ID Name. Category
101. Dumplings Chicken
102. Pizza Cheese
When I select chicken in combobox, the row of JTable with Chicken that is the first row should only get displayed. How do I do this?
Upvotes: 0
Views: 31
Reputation: 44414
Use a RowFilter.
You install a RowFilter on a TableRowSorter:
TableRowSorter<Dish> sorter = new TableRowSorter<>(table.getModel());
table.setRowSorter(sorter);
int categoryColumnIndex = 2;
combobox.addActionListener(e -> {
String value = combobox.getSelectedItem().toString();
sorter.setRowFilter(
RowFilter.regexFilter(
Pattern.quote(value),
categoryColumnIndex));
});
Upvotes: 1