本文介绍了带有HTML的JLabel包含“&lt;”和“&gt;”。人物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有时我会在Java Swing的JLabel中使用HTML。最后,我碰到了一些有点让我困惑的事情...... 我的代码: 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 \\\ frame.add(lbl1); frame.add(lbl2); frame.add(lbl3); frame.pack(); frame.setVisible(true); } 任何人都可以解释我为什么在标签1和3中看到>字符,而<不可见?我假设<和u003C的解释方式完全一样, HTML字符不能被正确解释,但是如果是,为什么显示>,这也是HTML中的特殊字符? & lt 和& 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 &gt; 100 and 90 &lt; 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 &lt and &gt 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 &lt; or &#34;. 这篇关于带有HTML的JLabel包含“&lt;”和“&gt;”。人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 15:12