EditorPane and TextPane: fixed font and text color when using HTML content (#9)

This commit is contained in:
Karl Tauber
2019-10-20 18:02:20 +02:00
parent 5a952c187c
commit 41ecbccc76
5 changed files with 120 additions and 1 deletions

View File

@@ -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

View File

@@ -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