0

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
bluesony
  • 459
  • 1
  • 5
  • 28
  • 1
    yes is possible, nothing special, read 1. [Oracle tutorial How to use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html), 2. [Oracle tutorial How to use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data), 3. [Oracle tutorial How to use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting) – mKorbel Dec 20 '13 at 10:39
  • you need to showing some effort, e.g. search [in post by @MadProgrammer](http://stackoverflow.com/search?q=user%3A992484+[jtable]+abstracttablemodel), hes loves JTable + AbstractTableModel + util.List – mKorbel Dec 20 '13 at 10:47
  • thanks mKorbel for the tutorials ! – bluesony Dec 20 '13 at 10:59
  • 1
    glad if help you :-), btw in tutorial is exactly described everything that you can find out in posts by MadProgrammer, there nothing missing, I'm suggest to ask an questions, but probably I forgot to define that a new questions that meets with our standards here, much luck – mKorbel Dec 20 '13 at 11:06

2 Answers2

1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

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.