From 8b10d3ba5a5321128b841946fb5fb2ba41b634b8 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 2 Jul 2022 23:26:34 +0200 Subject: [PATCH] Native window decorations: fixed missing top window border in dark themes if window drop shadows are disabled in system settings (issue #554) --- CHANGELOG.md | 3 +++ .../flatlaf/ui/JBRCustomDecorations.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63f3c27c..73ae6668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ FlatLaf Change Log Windows because they have bad vertically placement. - Native window decorations (Windows 10/11 only): Do not use window decorations if system property `sun.java2d.opengl` is `true` on Windows 10. (issue #540) +- Native window decorations (Windows 10 only): Fixed missing top window border + in dark themes if window drop shadows are disabled in system settings. (issue + #554) ## 2.3 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 38482637..39604e74 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -195,11 +195,13 @@ public class JBRCustomDecorations { private static JBRWindowTopBorder instance; - private final Color defaultActiveBorder = new Color( 0x707070 ); + private final Color activeLightColor = new Color( 0x707070 ); + private final Color activeDarkColor = new Color( 0x2D2E2F ); private final Color inactiveLightColor = new Color( 0xaaaaaa ); + private final Color inactiveDarkColor = new Color( 0x494A4B ); private boolean colorizationAffectsBorders; - private Color activeColor = defaultActiveBorder; + private Color activeColor; static JBRWindowTopBorder getInstance() { if( instance == null ) @@ -250,7 +252,7 @@ public class JBRCustomDecorations private Color calculateActiveBorderColor() { if( !colorizationAffectsBorders ) - return defaultActiveBorder; + return null; Color colorizationColor = getColorizationColor(); if( colorizationColor != null ) { @@ -285,15 +287,11 @@ public class JBRCustomDecorations public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { Window window = SwingUtilities.windowForComponent( c ); boolean active = window != null && window.isActive(); + boolean dark = FlatLaf.isLafDark(); - // paint top border - // - in light themes - // - in dark themes only for active windows if colorization affects borders - boolean paintTopBorder = !FlatLaf.isLafDark() || (active && colorizationAffectsBorders); - if( !paintTopBorder ) - return; - - g.setColor( active ? activeColor : inactiveLightColor ); + g.setColor( active + ? (activeColor != null ? activeColor : (dark ? activeDarkColor : activeLightColor)) + : (dark ? inactiveDarkColor : inactiveLightColor) ); HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl ); }