Question

I have created a JTable using AbstractTableModel in which I added a collection of objects (ArrayList). I want to be able to search through the objects and return in the same JTable only the ones that meet a conditions (for example the names starts with "St"). Theoretically, how can I do that? Do I have to make new ArrayLists for every condition, and store these searched (and returned) objects there? Is there a better/simpler way? Thanks

Was it helpful?

Solution 2

here is the thing, if you are looking for syntaxic filtering this functionality already exists in java as TableRowSorter which can be combined with row filter to set the subList and show it.

OTHER TIPS

As shown here, you can access a Collection in your implementation of AbstractTableModel. As shown here, you can sort and filter the results without modifying the original data structure. A complete example is examined here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top