【发布时间】:2014-04-20 04:14:15
【问题描述】:
我有时在 Java Swing 中的 JLabels 中使用 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 中的一个特殊字符,被显示?
&lt 和 &gt 是唯一正确的选项吗?
【问题讨论】:
标签: java html swing special-characters jlabel