【发布时间】:2014-03-18 13:35:22
【问题描述】:
我有ArrayList,我在其中放置了作者、标题和值(整数)。我想将它们放在标签中并在单独的行中打印。但我得到的是文本打印在一行中。
for (Book book : listofbooks) {
labelis.setText(labelis.getText() + "\nName: " + book.getName() + "Tile: " + book.getTitle() + "Number of books: " + book.getHowMany());
}
panel.add(labelis);
为什么\n 不起作用?
编辑:解决方案:
for (Book book : listofbooks) {
label.setText( "<html> "
+ label.getText()
+ "<br>Name: " + book.getName()
+ "Tile: " + book.getTitle()
+ "Number of books: "
+ book.getHowMany()
);
}
label.setText(label.getText()+ "</html>");
【问题讨论】:
标签: java html string swing label