【发布时间】:2020-12-18 20:55:36
【问题描述】:
我正在尝试在 java swing 窗口中设置几个换行符,但由于某种原因,所有内容都打印在一行上。
这是我的代码:
private JLabel lblOutput;
guess = 79;
numberOfTries = 5;
message = guess + " is correct. " + "\n" + "Let's play again! " + "\n" + "And it only took you " + numberOfTries + " number of tries!";
lblOutput.setText(message);
上面的输出是:
79 is correct. Let's play again! And it only took you 5 number of tries!
我做错了什么?
【问题讨论】:
-
如果要显示多行字符串,可以使用 JTextArea。
标签: java swing jlabel multiline