Reputation: 994
in console we can do that like this :
for(int i = 0 ; i <list.size();i++){
System.out.print("name :"+list.get(i).getName());
System.out.print(" year :"+list.get(i).getYear());
System.out.println();
}
if we know the size we can creat many label and do that
label.setText("");
what is the best way to do that in swing if we don't know the size of our list ?
Upvotes: 0
Views: 1310
Reputation: 168825
System.out.print("name :"+list.get(i).getName());
System.out.print(" year :"+list.get(i).getYear());
System.out.println();
For tabular information, use a JTable
. See How to Use Tables for more details and code.
Another tips: for command line output, look to Formatting Numeric Print Output.
Upvotes: 3
Reputation: 44808
You can use HTML to format text in any Swing component that displays text.
StringBuilder b = new StringBuilder("<html>");
for(String s : list) {
b.append(s);
b.append("<br>");
}
label.setText(b.toString()); // multiline JLabel
Upvotes: 2