diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1099fb47..8e6df84d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ FlatLaf Change Log
- ComboBox: Use small border if used as table editor.
- ToolBar: Disable focusability of buttons in toolbar.
- OptionPane: Fixed rendering of longer HTML text. (issue #12)
+- EditorPane and TextPane: Fixed font and text color when using HTML content.
+ (issue #9)
- SwingX: Support `JXBusyLabel`, `JXDatePicker`, `JXHeader`, `JXHyperlink`,
`JXMonthView`, `JXTaskPaneContainer` and `JXTaskPane`. (issue #8)
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java
index f386cc3c..f0deace0 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Dimension;
import javax.swing.JComponent;
+import javax.swing.JEditorPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicEditorPaneUI;
@@ -37,6 +38,8 @@ public class FlatEditorPaneUI
{
protected int minimumWidth;
+ private Object oldHonorDisplayProperties;
+
public static ComponentUI createUI( JComponent c ) {
return new FlatEditorPaneUI();
}
@@ -46,6 +49,17 @@ public class FlatEditorPaneUI
super.installDefaults();
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
+
+ // use component font and foreground for HTML text
+ oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
+ getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, true );
+ }
+
+ @Override
+ protected void uninstallDefaults() {
+ super.uninstallDefaults();
+
+ getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
}
@Override
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java
index 8d5457df..60c8f220 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Dimension;
import javax.swing.JComponent;
+import javax.swing.JEditorPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTextPaneUI;
@@ -37,6 +38,8 @@ public class FlatTextPaneUI
{
protected int minimumWidth;
+ private Object oldHonorDisplayProperties;
+
public static ComponentUI createUI( JComponent c ) {
return new FlatTextPaneUI();
}
@@ -46,6 +49,17 @@ public class FlatTextPaneUI
super.installDefaults();
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
+
+ // use component font and foreground for HTML text
+ oldHonorDisplayProperties = getComponent().getClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES );
+ getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, true );
+ }
+
+ @Override
+ protected void uninstallDefaults() {
+ super.uninstallDefaults();
+
+ getComponent().putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, oldHonorDisplayProperties );
}
@Override
diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java
index a346d949..c937e7e2 100644
--- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java
+++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java
@@ -143,7 +143,14 @@ public class FlatComponentsTest
JToggleButton toggleButton7 = new JToggleButton();
JLabel scrollBarLabel = new JLabel();
JScrollBar scrollBar1 = new JScrollBar();
+ JLabel label4 = new JLabel();
JScrollBar scrollBar4 = new JScrollBar();
+ JPanel panel3 = new JPanel();
+ JLabel label3 = new JLabel();
+ JScrollPane scrollPane15 = new JScrollPane();
+ JEditorPane editorPane6 = new JEditorPane();
+ JScrollPane scrollPane16 = new JScrollPane();
+ JTextPane textPane6 = new JTextPane();
JLabel separatorLabel = new JLabel();
JSeparator separator1 = new JSeparator();
JPanel panel2 = new JPanel();
@@ -719,11 +726,52 @@ public class FlatComponentsTest
scrollBar1.setOrientation(Adjustable.HORIZONTAL);
add(scrollBar1, "cell 1 14,growx");
+ //---- label4 ----
+ label4.setText("HTML:");
+ add(label4, "cell 5 14");
+
//---- scrollBar4 ----
scrollBar4.setOrientation(Adjustable.HORIZONTAL);
scrollBar4.setEnabled(false);
add(scrollBar4, "cell 1 15,growx");
+ //======== panel3 ========
+ {
+ panel3.setLayout(new MigLayout(
+ "insets 0,hidemode 3,gap 5 5,ltr",
+ // columns
+ "[]",
+ // rows
+ "[]" +
+ "[]" +
+ "[]"));
+
+ //---- label3 ----
+ label3.setText("JLabel HTML
Sample content
text");
+ panel3.add(label3, "cell 0 0");
+
+ //======== scrollPane15 ========
+ {
+
+ //---- editorPane6 ----
+ editorPane6.setContentType("text/html");
+ editorPane6.setText("JEditorPane HTML
Sample content
text");
+ scrollPane15.setViewportView(editorPane6);
+ }
+ panel3.add(scrollPane15, "cell 0 1,grow");
+
+ //======== scrollPane16 ========
+ {
+
+ //---- textPane6 ----
+ textPane6.setContentType("text/html");
+ textPane6.setText("JTextPane HTML
Sample content
text");
+ scrollPane16.setViewportView(textPane6);
+ }
+ panel3.add(scrollPane16, "cell 0 2,grow");
+ }
+ add(panel3, "cell 5 15 1 7,aligny top,grow 100 0");
+
//---- separatorLabel ----
separatorLabel.setText("JSeparator:");
add(separatorLabel, "cell 0 16");
diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd
index f9b23011..852e61ae 100644
--- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd
+++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd
@@ -678,6 +678,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 14,growx"
} )
+ add( new FormComponent( "javax.swing.JLabel" ) {
+ name: "label4"
+ "text": "HTML:"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 5 14"
+ } )
add( new FormComponent( "javax.swing.JScrollBar" ) {
name: "scrollBar4"
"orientation": 0
@@ -685,6 +691,41 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 15,growx"
} )
+ add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
+ "$columnConstraints": "[]"
+ "$rowConstraints": "[][][]"
+ "$layoutConstraints": "insets 0,hidemode 3,gap 5 5,ltr"
+ } ) {
+ name: "panel3"
+ add( new FormComponent( "javax.swing.JLabel" ) {
+ name: "label3"
+ "text": "JLabel HTML
Sample content
text"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 0 0"
+ } )
+ add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
+ name: "scrollPane15"
+ add( new FormComponent( "javax.swing.JEditorPane" ) {
+ name: "editorPane6"
+ "contentType": "text/html"
+ "text": "JEditorPane HTML
Sample content
text"
+ } )
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 0 1,grow"
+ } )
+ add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
+ name: "scrollPane16"
+ add( new FormComponent( "javax.swing.JTextPane" ) {
+ name: "textPane6"
+ "contentType": "text/html"
+ "text": "JTextPane HTML
Sample content
text"
+ } )
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 0 2,grow"
+ } )
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 5 15 1 7,aligny top,grow 100 0"
+ } )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "separatorLabel"
"text": "JSeparator:"
@@ -837,7 +878,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
- "size": new java.awt.Dimension( 790, 715 )
+ "size": new java.awt.Dimension( 790, 750 )
} )
}
}