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

Était-ce utile?

La 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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top