我之前没有在JTextPane中使用过HTML并且今天玩这个。我遇到了奇怪的输出。
以下是我的简单代码,htmlStr
包含标记<aa>
:
public class HtmlInJTextPaneTest extends JFrame {
private JTextPane jtp;
private String htmlStr= "<html><body><b>What is this</b> <aa > ?? </body></html>";
public HtmlInJTextPaneTest() {
jtp = new JTextPane();
jtp.setContentType("text/html");
jtp.setText(htmlStr);
//jtp.setEditable(false);
//jFrame setup
add(jtp);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200, 100);
setVisible(true);
}
public static void main(String[] args) {
new HtmlInJTextPaneTest();
}
}
这个输出是:
我不知道为什么标签名aa
出现在框中(似乎是输入字段)?
当我在JTextPane
对象jtp
上设置可编辑的false时,它会消失。
jtp.setEditable(false);
你能解释一下吗?