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
  • 6,030
  • 2
  • 25
  • 34
Alptugay
  • 1,676
  • 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
  • 4,040
  • 3
  • 28
  • 42
1
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319