[英]Java - HTML tags for JLabel
I'm trying to get a JLabel to display new line characters by using HTML tags. 我试图通过使用HTML标签让JLabel显示新的行字符。 But the text I want is obtained from a method.
但我想要的文字是从一种方法中获得的。 Here's the line of code:
这是代码行:
myLabel.setText("<html><pre>myCart.toString()</pre></html>");
But, this literally sets the text of the label to myCart.toString()
, not to the String that is returned by the method. 但是,这确实将标签的文本设置为
myCart.toString()
,而不是该方法返回的String。 Is there a way around this? 有没有解决的办法?
Do you mean? 你的意思是?
myLabel.setText("<html><pre>" + myCart.toString() + "</pre></html>");
or just: 要不就:
myLabel.setText("<html><pre>" + myCart + "</pre></html>");
since toString()
will be called implicitly. 因为
toString()
将被隐式调用。
myLabel.setText(MessageFormat.format("<html><pre>{0}</pre></html>",myCart.toString()));
" “
myCart.toString()"
should be 应该
" “
" + myCart.toString()+ ""“+ myCart.toString()+”
But I am only repeating what Eng.Fouad said 但我只是重复Eng.Fouad所说的话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.