java - 在 JEditorPane 中设置默认字体

标签 java swing fonts jeditorpane

editorPane.setContentType("text/html");    
editorPane.setFont(new Font("Segoe UI", 0, 14));
editorPane.setText("Hello World");

这不会改变文本的字体。我需要知道如何使用 HTML 编辑器工具包设置 JEditorPane 的默认字体。

编辑:

enter image description here

最佳答案

试试这个:

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/

相关文章:

python - 如何在主循环期间更改 Tkinter 应用程序的默认字体?

java - writableRaster 中像素字段的格式

java - Gwt NavigableSet 找不到源

java - java中使用Graphics绘制线条

fonts - SHX字体规范和字体文件的许可

javascript - 如何添加默认文本大小功能 - Javascript

java - Hibernate Oracle 表空间注解

java - 列出 clojure 中可用的 java 包和类

java - 使用单独的线程更新 JTable

java - 如何将 JScrollBar 添加到 Java 窗口生成器中的 JTextArea?