Skip to content

Commit

Permalink
Menu: fixed missing background on hover if top-level JMenu is opaque …
Browse files Browse the repository at this point in the history
…and `selectionInsets` or `selectionArc` are set (PR #536)
  • Loading branch information
DevCharly committed Oct 30, 2022
1 parent 0c5016f commit 873a7e8
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java
Expand Up @@ -251,6 +251,8 @@ protected FlatMenuRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon,
/** @since 3 */
@Override
protected void paintBackground( Graphics g ) {
super.paintBackground( g );

if( ((JMenu)menuItem).isTopLevelMenu() && isHover() ) {
// paint hover background
Color color = deriveBackground( getStyleFromMenuBarUI( ui -> ui.hoverBackground, hoverBackground ) );
Expand All @@ -259,10 +261,7 @@ protected void paintBackground( Graphics g ) {
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
} else
paintSelection( g, color, selectionInsets, selectionArc );
return;
}

super.paintBackground( g );
}

/** @since 3 */
Expand All @@ -289,14 +288,6 @@ protected void paintSelection( Graphics g, Color selectionBackground, Insets sel
super.paintSelection( g, selectionBackground, selectionInsets, selectionArc );
}

@Override
protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) {
if( ((JMenu)menuItem).isTopLevelMenu() && !isUnderlineSelection() )
selectionForeground = getStyleFromMenuBarUI( ui -> ui.selectionForeground, menuBarSelectionForeground, selectionForeground );

super.paintText( g, textRect, text, selectionForeground, disabledForeground );
}

/** @since 3 */
@Override
protected void paintUnderlineSelection( Graphics g, Color underlineSelectionBackground,
Expand All @@ -312,6 +303,14 @@ protected void paintUnderlineSelection( Graphics g, Color underlineSelectionBack
super.paintUnderlineSelection( g, underlineSelectionBackground, underlineSelectionColor, underlineSelectionHeight );
}

@Override
protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) {
if( ((JMenu)menuItem).isTopLevelMenu() && !isUnderlineSelection() )
selectionForeground = getStyleFromMenuBarUI( ui -> ui.selectionForeground, menuBarSelectionForeground, selectionForeground );

super.paintText( g, textRect, text, selectionForeground, disabledForeground );
}

private boolean isHover() {
ButtonModel model = menuItem.getModel();
return model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled();
Expand Down

0 comments on commit 873a7e8

Please sign in to comment.