Reputation: 23445
I'm sure this is possible but I am having trouble finding the appropriate documentation or a simple example for this situation.
For example's sake, lets say I have an object such as this:
public class Person {
private final String name;
private final int age;
private final String address;
// Constructor, Getters and Setters
}
Now I would like to be able to do something like this:
myTableModel.addColumn("name");
myTableModel.addColumn("age");
myTableModel.addColumn("address");
myJTable.setModel(myTableModel);
for (Person person : people) {
myTableModel.addRow(person);
}
And then each column would use the row's Person object to "get" its appropriate information to display.
Upvotes: 3
Views: 2210
Reputation: 38152
Create a custom TableModel. Here is a sample I wrote some time ago:
Instead of the NbBundle you can also use a ResourceBundle, if you're not building your application on top of the NetBeans Platform (though I recommend to use a RCP).
Upvotes: 3