为什么JLabel是第一个字符时不显示"/"? [英] Why does JLabel not display '/' when it is the first character?
问题描述
我有一个带有JLabel的旋转面板. JLabel看起来像这样:
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:
酒吧
Foo
酒吧
由于某种原因,第一行消失了.如果我删除斜杠或删除html标记,它会按预期工作.有没有办法使第一行显示为斜线?出现这种情况的原因是,我们有由第三方数据填充的JLabel.我可以以编程方式删除斜杠,但是如果有办法的话,我宁愿在UI中显示它.我们正在使用html和BR标签,以确保每个值都在单独的行中.
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.
推荐答案
我猜这是一个解析问题.如果您添加body标记,它将起作用:
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>"
这篇关于为什么JLabel是第一个字符时不显示"/"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!