mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
MenuBar:
- use derived colors for menu bar hover - use derived colors for menu item selected background - top-level JMenu now uses foreground color from parent JMenuBar This allows changing menu bar background to dark with: UIManager.put( "MenuBar.background", Color.DARK_GRAY ); UIManager.put( "MenuBar.foreground", Color.WHITE ); or menuBar.setBackground( Color.DARK_GRAY ); menuBar.setForeground( Color.WHITE ); (issue #117)
This commit is contained in:
@@ -261,7 +261,9 @@ debug*/
|
||||
|
||||
// paint background
|
||||
g.setColor( armedOrSelected
|
||||
? (isUnderlineSelection() ? underlineSelectionBackground : selectionBackground)
|
||||
? (isUnderlineSelection()
|
||||
? deriveBackground( underlineSelectionBackground )
|
||||
: selectionBackground)
|
||||
: menuItem.getBackground() );
|
||||
g.fillRect( 0, 0, width, height );
|
||||
|
||||
@@ -283,12 +285,20 @@ debug*/
|
||||
}
|
||||
}
|
||||
|
||||
protected Color deriveBackground( Color background ) {
|
||||
Color baseColor = menuItem.isOpaque()
|
||||
? menuItem.getBackground()
|
||||
: FlatUIUtils.getParentBackground( menuItem );
|
||||
|
||||
return FlatUIUtils.deriveColor( background, baseColor );
|
||||
}
|
||||
|
||||
protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon ) {
|
||||
// if checkbox/radiobutton menu item is selected and also has a custom icon,
|
||||
// then use filled icon background to indicate selection (instead of using checkIcon)
|
||||
if( menuItem.isSelected() && checkIcon != null && icon != checkIcon ) {
|
||||
Rectangle r = FlatUIUtils.addInsets( iconRect, scale( checkMargins ) );
|
||||
g.setColor( isUnderlineSelection() ? underlineSelectionCheckBackground : checkBackground );
|
||||
g.setColor( deriveBackground( isUnderlineSelection() ? underlineSelectionCheckBackground : checkBackground ) );
|
||||
g.fillRect( r.x, r.y, r.width, r.height );
|
||||
}
|
||||
|
||||
@@ -303,7 +313,7 @@ debug*/
|
||||
}
|
||||
|
||||
int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
|
||||
Color foreground = menuItem.getForeground();
|
||||
Color foreground = (isTopLevelMenu( menuItem ) ? menuItem.getParent() : menuItem).getForeground();
|
||||
|
||||
paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
|
||||
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
|
||||
|
||||
@@ -151,7 +151,7 @@ public class FlatMenuUI
|
||||
if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
|
||||
model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
|
||||
{
|
||||
g.setColor( FlatUIUtils.deriveColor( hoverBackground, menuItem.getBackground() ) );
|
||||
g.setColor( deriveBackground( hoverBackground ) );
|
||||
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
|
||||
} else
|
||||
super.paintBackground( g, selectionBackground );
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
@disabledText=#777777
|
||||
@textComponentBackground=#45494A
|
||||
@menuBackground=darken(@background,5%)
|
||||
@menuHoverBackground=lighten(@menuBackground,10%)
|
||||
@menuCheckBackground=lighten(@menuBackground,10%)
|
||||
@menuCheckHoverBackground=lighten(@menuBackground,20%)
|
||||
@menuHoverBackground=lighten(@menuBackground,10%,derived)
|
||||
@menuCheckBackground=lighten(@menuBackground,10%,derived)
|
||||
@menuCheckHoverBackground=lighten(@menuBackground,20%,derived)
|
||||
@cellFocusColor=#000000
|
||||
@icon=#adadad
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
@disabledText=#8C8C8C
|
||||
@textComponentBackground=#ffffff
|
||||
@menuBackground=#fff
|
||||
@menuHoverBackground=darken(@menuBackground,10%)
|
||||
@menuCheckBackground=darken(@menuBackground,10%)
|
||||
@menuCheckHoverBackground=darken(@menuBackground,20%)
|
||||
@menuHoverBackground=darken(@menuBackground,10%,derived)
|
||||
@menuCheckBackground=darken(@menuBackground,10%,derived)
|
||||
@menuCheckHoverBackground=darken(@menuBackground,20%,derived)
|
||||
@cellFocusColor=#000000
|
||||
@icon=#afafaf
|
||||
|
||||
|
||||
Reference in New Issue
Block a user