我想在我的 JEditorPane
中添加 HTML,但文本显示不正确。
另外,当文本的高度大于编辑器的高度时,
光标转到滚动 Pane 的最后一行。
我的代码如下:
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");
最佳答案
我的问题已经解决了:
我在 .setText() 之前添加了以下行
editorPaneInfo.setContentType("text/html");
关于java - 在 Java Swing 的 JEditorPane 中添加 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20862891/