【发布时间】:2014-01-18 17:12:32
【问题描述】:
我想在JEditorPane 中添加 HTML,但文本显示不正确。
此外,当文本的高度大于编辑器的高度时,
光标移动到滚动窗格的最后一行。
我的代码如下:
JPanel JPInfo = new JPanel(new BorderLayout());
JPInfo.setBorder(BorderFactory.createTitledBorder("Information"));
editorPaneInfo = new JEditorPane();
editorPaneInfo.setEditable(false);
editorPaneInfo.setText("<html><p style=\"color:green\"> Test Test </p></html>");
JScrollPane editorScrollPaneInfo = new JScrollPane(editorPaneInfo);
editorScrollPaneInfo.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JPInfo.add(editorScrollPaneInfo,BorderLayout.CENTER);
已解决: 我在 setText 之前添加了以下行
editorPaneInfo.setContentType("text/html");
【问题讨论】:
-
1) 为了尽快获得更好的帮助,请发帖 SSCCE。 2) 尝试描述 a) 你预期会发生什么 b) 实际发生了什么,以及效用 c) 为什么你预期 (a) 会发生。屏幕截图可能会有所帮助。
-
我原以为文本是绿色的,但现在我解决了我的问题:我访问了以下链接 [stackoverflow.com/questions/5174070/… 并在我的代码中添加了
editorPaneInfo.setContentType("text/html");,现在一切正常!跨度> -
请回答您自己的问题,或者删除它..
标签: java html swing jeditorpane