我使用 JEditorPane 在 swing 应用程序中呈现一些 HTML。我使用了一个项目符号列表<ul><li>...</li></ul>
,我在输出中获得了过大的项目符号。相同的 HTML 块将在真实浏览器中显示正常大小的项目符号。
我在 Windows 7 / JDK 7 和 iirc 上也观察到了这一点,也在 Ubuntu 和 OpenJDK 1.7.0_09 上观察到了这一点。
这是已知的吗?有办法解决吗?
工作示例:
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
/**
*
*/
public class HTMLTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// create new frame
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(500, 500);
// create editor pane and fill with some html
JEditorPane pane = new JEditorPane();
pane.setContentType("text/html");
pane.setEditable(false);
pane.setText("<html><h1>Heading</h1>Text<ul><li>Bullet point</li></ul></html>");
// add editor pane to frame and set frame visible
frame.add(pane);
frame.setVisible(true);
}
}
PS:我现在正在使用
ul {
list-style-type: none;
margin-left: 10px
}
在一个CSS文件和
<li>• Item 1</li>
在 html 中有一个不错的要点。受 aterai 启发的解决方案。