From 681c0cd4fe3881c837d8fd51f91d3c06e48ba3f8 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 8 Mar 2025 19:30:14 +0100 Subject: [PATCH] HTML: fixed rendering of `
` in dark themes (issue #932) --- CHANGELOG.md | 1 + .../java/com/formdev/flatlaf/ui/StackUtils.java | 2 +- .../com/formdev/flatlaf/util/HiDPIUtils.java | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39833d21..a5822943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ FlatLaf Change Log - Fixed loading FlatLaf UI delegate classes when using FlatLaf in special application where multiple class loaders are involved. E.g. in Eclipse plugin or in LibreOffice extension. (issues #955 and #851) +- HTML: Fixed rendering of `
` in dark themes. (issue #932) #### Incompatibilities diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/StackUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/StackUtils.java index 0d833689..aff2ff08 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/StackUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/StackUtils.java @@ -21,7 +21,7 @@ import java.util.function.BiPredicate; /** * @author Karl Tauber */ -class StackUtils +public class StackUtils { private static final StackUtils INSTANCE = new StackUtilsImpl(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/HiDPIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/HiDPIUtils.java index 21976798..67af1f56 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/HiDPIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/HiDPIUtils.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.util; +import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; @@ -27,7 +28,9 @@ import java.awt.geom.Rectangle2D; import java.text.AttributedCharacterIterator; import javax.swing.JComponent; import javax.swing.RepaintManager; +import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatSystemProperties; +import com.formdev.flatlaf.ui.StackUtils; /** * @author Karl Tauber @@ -323,6 +326,19 @@ public class HiDPIUtils public void drawGlyphVector( GlyphVector g, float x, float y ) { super.drawGlyphVector( g, x, y + yCorrection ); } + + @Override + public void fillRect( int x, int y, int width, int height ) { + // fix hard coded black color in HRuleView.paint() of '
' + if( super.getColor() == Color.black && + StackUtils.wasInvokedFrom( "javax.swing.text.html.HRuleView", "paint", 4 ) ) + { + super.setColor( FlatLaf.isLafDark() ? Color.lightGray : Color.darkGray ); + super.fillRect( x, y, width, height ); + super.setColor( Color.black ); + } else + super.fillRect( x, y, width, height ); + } }; }