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?
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));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.