1

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)
dda
  • 5,760
  • 2
  • 24
  • 34
Alptugay
  • 1,602
  • 4
  • 22
  • 29

2 Answers2

1

If you're absolutely sure you'll only be returning FooBar object you just have to cast the objectsof the model into FooBar

Pierre Arlaud
  • 3,891
  • 3
  • 27
  • 40
1
Community
  • 1
  • 1
mKorbel
  • 109,107
  • 18
  • 130
  • 305