Setting default font in JEditorPane

Sanjeev picture Sanjeev · Sep 22, 2012 · Viewed 14.5k times · Source
editorPane.setContentType("text/html");    
editorPane.setFont(new Font("Segoe UI", 0, 14));
editorPane.setText("Hello World");

This does not change the font of the text. I need to know how to set the default font for the JEditorPane with HTML Editor Kit.

Edit:

enter image description here

Answer

Espinosa picture Espinosa · Mar 2, 2013

Try this one:

JEditorPane pane = new JEditorPane();
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
pane.setFont(SOME_FONT);

All credits to de-co-de blogger! Source: http://de-co-de.blogspot.co.uk/2008/02/setting-font-in-jeditorpane.html

I have just tested it. This made JEditorPane to use same font as JLabel

JEditorPane pane = new JEditorPane();
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
pane.setFont(someOrdinaryLabel.getFont());

Works perfectly.