Reputation: 312
I have ArrayList of Children and has a few properties ( full name (String),age(int),parent_id(int),id(int)). I'm using netbeans design view to create JFrame ( it's more easy for me to position elements).
In this JFRAME I have jList how I can set all rows from ArrayList at jList and format like that :
String.format("%s \t %d",ch.getFullName(),ch.getAge())
.
I tried to make it foreach element from arraylist but doesnt work.
Upvotes: 0
Views: 345
Reputation: 324207
A JTable is a better choice for rendering multiple columns of data. See the section from the Swing tutorial on How to Use Tables for more information.
The DefaultTableModel doesn't support an ArrayList with custom Objects so you could try using the Row Table Model.
Upvotes: 1
Reputation: 57421
Add all the Children classes to the JList
model and define a custom ListCellRenderer
. In the renderer get value and use the Children element to set text.
Upvotes: 3