我们如何在标签中更改? [英] How do we changeline in a label?

查看:80
本文介绍了我们如何在标签中更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,在设置文本时我想换行。
例如

I have a label and when setting the text I want to change line . For instance

String str="first line \n Secondline ";
JLabel label.setText(str);

我尝试了上面的代码,但它不起作用..如何更改字符串中的行?

I tried the above code but it does not work..How do I change line in a string ?

推荐答案

Swing不使用经典换行符。相反,由于我从未完全理解的原因,它使用HTML 3.2
因此,要正确显示文本,yopu必须依赖HTML内容:

Swing does not uses classical line breaks. Instead, for a reason I never fully understood, it uses HTML 3.2. As a consequence, to have your text correctly displayed, yopu have to rely upon HTML content :

String str= "<html>First line<br>Second line</html>"

但是,如果你真的想要,还有其他可能性 ......

However, if you really want to, there are other possibilities ...

这篇关于我们如何在标签中更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆