Skip to content

Commit

Permalink
MenuBar: top level menus now use MenuBar.font instead of `Menu.font…
Browse files Browse the repository at this point in the history
…` (issue #589)
  • Loading branch information
DevCharly committed Sep 22, 2022
1 parent 78e7839 commit f6c5db0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@ FlatLaf Change Log
This gives FlatLaf windows a more "native" feeling. (issue #482)
- MenuBar: Support different menu selection style UI defaults for `MenuBar` and
`MenuItem`. (issue #587)
- MenuBar: Top level menus now use `MenuBar.font` instead of `Menu.font`. (issue
#589)
- PasswordField: Reveal button is now hidden (and turned off) if password field
is disabled. (issue #501)
- TabbedPane: New option to disable tab run rotation in wrap layout. Set UI
Expand Down
Expand Up @@ -97,6 +97,7 @@ public class FlatMenuItemRenderer
@Styleable protected int underlineSelectionHeight = UIManager.getInt( "MenuItem.underlineSelectionHeight" );

private boolean iconsShared = true;
private final Font menuFont = UIManager.getFont( "Menu.font" );

protected FlatMenuItemRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon,
Font acceleratorFont, String acceleratorDelimiter )
Expand Down Expand Up @@ -193,7 +194,8 @@ protected Dimension getPreferredMenuItemSize() {

// layout icon and text
SwingUtilities.layoutCompoundLabel( menuItem,
menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(),
menuItem.getFontMetrics( isTopLevelMenu ? getTopLevelFont() : menuItem.getFont() ),
menuItem.getText(), getIconForLayout(),
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
viewRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
Expand Down Expand Up @@ -295,7 +297,8 @@ private void layout( Rectangle viewRect, Rectangle iconRect, Rectangle textRect,

// layout icon and text
SwingUtilities.layoutCompoundLabel( menuItem,
menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(),
menuItem.getFontMetrics( isTopLevelMenu ? getTopLevelFont() : menuItem.getFont() ),
menuItem.getText(), getIconForLayout(),
menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
labelRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );
Expand Down Expand Up @@ -405,9 +408,10 @@ protected void paintText( Graphics g, Rectangle textRect, String text, Color sel
}

int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1;
Color foreground = (isTopLevelMenu( menuItem ) ? menuItem.getParent() : menuItem).getForeground();
boolean isTopLevelMenu = isTopLevelMenu( menuItem );
Color foreground = (isTopLevelMenu ? menuItem.getParent() : menuItem).getForeground();

paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(),
paintText( g, menuItem, textRect, text, mnemonicIndex, isTopLevelMenu ? getTopLevelFont() : menuItem.getFont(),
foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground );
}

Expand Down Expand Up @@ -494,6 +498,11 @@ protected boolean isUnderlineSelection() {
return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) );
}

private Font getTopLevelFont() {
Font font = menuItem.getFont();
return (font != menuFont) ? font : menuItem.getParent().getFont();
}

private Icon getIconForPainting() {
Icon icon = menuItem.getIcon();

Expand Down

0 comments on commit f6c5db0

Please sign in to comment.