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 ?
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 .
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
label.setText(label.getText() + " " + s);Use For-Each
Loop.
for example:
for (String s : listOfStringType){
label.setText(label.getText() + " " + s);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.