editorPane.setContentType("text/html");
editorPane.setFont(new Font("Segoe UI", 0, 14));
editorPane.setText("Hello World");
这不会改变文本的字体。我需要知道如何使用 HTML 编辑器工具包设置 JEditorPane 的默认字体。
编辑:
最佳答案
试试这个:
JEditorPane pane = new JEditorPane();
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
pane.setFont(SOME_FONT);
感谢de-co-de博主!资源: http://de-co-de.blogspot.co.uk/2008/02/setting-font-in-jeditorpane.html
我刚测试过。这使得 JEditorPane 使用与 JLabel 相同的字体
JEditorPane pane = new JEditorPane();
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
pane.setFont(someOrdinaryLabel.getFont());
完美运行。
关于java - 在 JEditorPane 中设置默认字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12542733/