Why does JLabel not display '/' when it is the first character?

﹥>﹥吖頭↗ 提交于 2019-12-10 13:54:09

问题


I have an swing panel with a JLabel inside of it. The JLabel looks like this:

new JLabel("<html>/Foo <br/>/Bar <br/>/Foo<br/>/Bar</html>");

However it displays in the UI like the following:

Bar

Foo

Bar

For some reason, the first line just disappears. If I take out the slash or remove the html tags, it works as expected. Is there a way to make the first line show up with the slash? The reason this even showed up is that we have JLabels which are populated by third party data. I could programatically remove the slash, but I would prefer to show it in the UI if there is a way to do it. We are using html and the BR tags in order to make sure each value is on a separate line.


回答1:


I guess its a parsing problem. It works if you add the body tags:

"<html><body>/Foo <br/>/Bar <br/>/Foo<br/>/Bar</body></html>"



回答2:


This is a known bug. You can find it here in the bug lists.



来源:https://stackoverflow.com/questions/7408160/why-does-jlabel-not-display-when-it-is-the-first-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!