Reputation: 1686
Let's assume that I have a class like this:
public Class FooBar {
String foo;
String bar;
String unvisibleField;
String id;
}
Then I have created a table using DefaultTableModel
and adding elements to it like this (I am not showing all attributes of the class to the user):
for(int i=0;i<fooBarList.size();i++){
model.addRow(new String[]{fooBarList.get(i).getFoo(), fooBarList.get(i).getBar()});
}
But I want to retrieve the FooBar class object from the table. Something like this:
model.getRow()
will return a FooBar object
So probably I will also need something like
model.addRow(FooBar item)
Upvotes: 1
Views: 52
Reputation: 109813
this easiest and direct (and correct too) way how to add a new data to (Abstract/Default) TableModel
please try and read Row Table Model/List Table Model by @camickr for your idea to put / synchronize FooBar item
on this forum are answers how to implementing AbstractTableModel based on HashXxx or List, you have to check if methods in the AbstractTableModel firing right and required events
Upvotes: 1
Reputation: 4133
If you're absolutely sure you'll only be returning FooBar object you just have to cast the objectsof the model into FooBar
Upvotes: 1