我不时在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>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);
}
有人可以解释我为什么在标签1和标签3中我看到">"
字符,而"<"
不可见?我假设,"<"
和"u003C"
以完全相同的方式解释,并且因为无法正确解释特殊的HTML字符,但如果是,为什么">"
,这也是一个特殊的显示HTML中的字符?
<
和>
是唯一正确的选项吗?
答案 0 :(得分:2)
JLabel实现假定原始<
是html元素的无效开始标记的一部分,并将其删除。您可以使用<
或"
。
答案 1 :(得分:0)
Are < and > the only correct options?
根据知识,你是对的。这两个是普遍接受的。
<
表示小于。
>
表示大于。