Menu: fixed missing background on hover if top-level JMenu is opaque and selectionInsets or selectionArc are set (PR #536)

This commit is contained in:
Karl Tauber
2022-10-30 10:10:22 +01:00
parent 0c5016fe89
commit 873a7e8572

View File

@@ -251,6 +251,8 @@ public class FlatMenuUI
/** @since 3 */ /** @since 3 */
@Override @Override
protected void paintBackground( Graphics g ) { protected void paintBackground( Graphics g ) {
super.paintBackground( g );
if( ((JMenu)menuItem).isTopLevelMenu() && isHover() ) { if( ((JMenu)menuItem).isTopLevelMenu() && isHover() ) {
// paint hover background // paint hover background
Color color = deriveBackground( getStyleFromMenuBarUI( ui -> ui.hoverBackground, hoverBackground ) ); Color color = deriveBackground( getStyleFromMenuBarUI( ui -> ui.hoverBackground, hoverBackground ) );
@@ -259,10 +261,7 @@ public class FlatMenuUI
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
} else } else
paintSelection( g, color, selectionInsets, selectionArc ); paintSelection( g, color, selectionInsets, selectionArc );
return;
} }
super.paintBackground( g );
} }
/** @since 3 */ /** @since 3 */
@@ -289,14 +288,6 @@ public class FlatMenuUI
super.paintSelection( g, selectionBackground, selectionInsets, selectionArc ); 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 */ /** @since 3 */
@Override @Override
protected void paintUnderlineSelection( Graphics g, Color underlineSelectionBackground, protected void paintUnderlineSelection( Graphics g, Color underlineSelectionBackground,
@@ -312,6 +303,14 @@ public class FlatMenuUI
super.paintUnderlineSelection( g, underlineSelectionBackground, underlineSelectionColor, underlineSelectionHeight ); 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() { private boolean isHover() {
ButtonModel model = menuItem.getModel(); ButtonModel model = menuItem.getModel();
return model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled(); return model.isRollover() && !model.isArmed() && !model.isSelected() && model.isEnabled();