From f149d2b7cda3668fb16923f983b5c58fb21c964d Mon Sep 17 00:00:00 2001 From: mmatessi <17149962+basix86@users.noreply.github.com> Date: Fri, 27 Nov 2020 19:14:28 +0100 Subject: [PATCH] MenuBar.underlineSelectionColor --- .../com/formdev/flatlaf/ui/FlatMenuItemRenderer.java | 4 ++-- .../src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java | 9 ++++++--- .../resources/com/formdev/flatlaf/FlatLaf.properties | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java index b49d2df1..6c1d6b24 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java @@ -246,7 +246,7 @@ public class FlatMenuItemRenderer g.setColor( Color.orange ); g.drawRect( arrowRect.x, arrowRect.y, arrowRect.width - 1, arrowRect.height - 1 ); debug*/ - paintBackground( g, selectionBackground ); + paintBackground( g, selectionBackground, underlineSelectionColor ); paintIcon( g, iconRect, getIconForPainting() ); paintText( g, textRect, menuItem.getText(), selectionForeground, disabledForeground ); paintAccelerator( g, accelRect, getAcceleratorText(), acceleratorForeground, acceleratorSelectionForeground, disabledForeground ); @@ -254,7 +254,7 @@ debug*/ paintArrowIcon( g, arrowRect, arrowIcon ); } - protected void paintBackground( Graphics g, Color selectionBackground ) { + protected void paintBackground( Graphics g, Color selectionBackground, Color underlineSelectionColor ) { boolean armedOrSelected = isArmedOrSelected( menuItem ); if( menuItem.isOpaque() || armedOrSelected ) { int width = menuItem.getWidth(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java index 503e3981..2edfc3b2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java @@ -60,13 +60,16 @@ import javax.swing.plaf.basic.BasicMenuUI; * * * @uiDefault MenuItem.iconTextGap int - * @uiDefault MenuBar.hoverBackground Color + * @uiDefault MenuBar.hoverBackground + * @uiDefault MenuBar.underlineSelectionColor Color * * @author Karl Tauber */ public class FlatMenuUI extends BasicMenuUI { + protected final Color menuBarUnderlineSelectionColor = UIManager.getColor( "MenuBar.underlineSelectionColor" ); + private Color hoverBackground; private FlatMenuItemRenderer renderer; @@ -154,7 +157,7 @@ public class FlatMenuUI } @Override - protected void paintBackground( Graphics g, Color selectionBackground ) { + protected void paintBackground( Graphics g, Color selectionBackground, Color menuItemUnderlineSelectionColor ) { ButtonModel model = menuItem.getModel(); if( model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() ) @@ -162,7 +165,7 @@ public class FlatMenuUI g.setColor( deriveBackground( hoverBackground ) ); g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); } else - super.paintBackground( g, selectionBackground ); + super.paintBackground( g, selectionBackground, ((JMenu)menuItem).isTopLevelMenu() ? menuBarUnderlineSelectionColor : menuItemUnderlineSelectionColor ); } } } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 0b94527b..ac52502d 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -337,6 +337,7 @@ MenuBar.border=com.formdev.flatlaf.ui.FlatMenuBarBorder MenuBar.background=@menuBackground MenuBar.hoverBackground=@menuHoverBackground MenuBar.itemMargins=3,8,3,8 +MenuBar.underlineSelectionColor=$TabbedPane.underlineColor #---- MenuItem ----