带有HTML的JLabel包含“<”和“>”。人物 [英] JLabel with HTML containing "<" and ">" characters
问题描述
我的代码:
public static void main(String [] args){
JFrame frame = new JFrame();
BoxLayout layout = new BoxLayout(frame.getContentPane(),BoxLayout.PAGE_AXIS);
frame.getContentPane()。setLayout(layout);
JLabel lbl1 = new JLabel(< html>标签1:300> 100和90< 200< / html>);
JLabel lbl2 = new JLabel(< html> Label 2:300& gt; 100 and 90& lt; 200< / html>);
JLabel lbl3 = new JLabel(< html> Label 3:300 \\\> 100 and 90 \\\< 200< / html>);
frame.add(lbl1);
frame.add(lbl2);
frame.add(lbl3);
frame.pack();
frame.setVisible(true);
}
任何人都可以解释我为什么在标签1和3中看到>
字符,而<
不可见?我假设<
和u003C
的解释方式完全一样, HTML字符不能被正确解释,但是如果是,为什么显示>
,这也是HTML中的特殊字符?
& gt
只有正确的选项?
JLabel实现假定原始<
是html元素的无效开始标记的一部分,并将其删除。您可以使用& lt;
或&#34;
。
From time to time I use HTML in JLabels in Java Swing. Lastly I've came across something a little bit, for me, confusing...
My code:
public static void main(String[] args) {
JFrame frame = new JFrame();
BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS);
frame.getContentPane().setLayout(layout);
JLabel lbl1 = new JLabel("<html>Label 1: 300 > 100 and 90 < 200 </html>");
JLabel lbl2 = new JLabel("<html>Label 2: 300 > 100 and 90 < 200 </html>");
JLabel lbl3 = new JLabel("<html>Label 3: 300 \u003E 100 and 90 \u003C 200 </html>");
frame.add(lbl1);
frame.add(lbl2);
frame.add(lbl3);
frame.pack();
frame.setVisible(true);
}
Could anyone explain me why in labels 1 and 3 I see ">"
character, while "<"
is not visible? I assume, that "<"
and "u003C"
are interpreted in exactly the same way, and as a special HTML character cannot be correctly interpreted, but if yes, why ">"
, which is also a special character in HTML, is displayed?
Are <
and >
the only correct options?
The JLabel implementation assumes a raw <
was part of an invalid opening tag for an html element, and it drops it. You can use <
or "
.
这篇关于带有HTML的JLabel包含“<”和“>”。人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!