PopupMenu on macOS: enabled drop shadows for popup menus and combobox popups (issue #94)

This commit is contained in:
Karl Tauber
2020-05-05 19:20:48 +02:00
parent b228dbb2df
commit 27a347db34
2 changed files with 23 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ FlatLaf Change Log
and right margins. (issue #54)
- Hide mnemonics if window is deactivated (e.g. <kbd>Alt+Tab</kbd> to another
window). (issue #43)
- macOS: Enabled drop shadows for popup menus and combobox popups. (issue #94)
- macOS: Fixed NPE if using `JMenuBar` in `JInternalFrame` and macOS screen menu
bar is enabled (with `-Dapple.laf.useScreenMenuBar=true`). (issue #90)

View File

@@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPopupMenuUI;
import com.formdev.flatlaf.util.SystemInfo;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPopupMenu}.
@@ -35,7 +36,28 @@ import javax.swing.plaf.basic.BasicPopupMenuUI;
public class FlatPopupMenuUI
extends BasicPopupMenuUI
{
private boolean oldLightWeightPopupEnabled;
public static ComponentUI createUI( JComponent c ) {
return new FlatPopupMenuUI();
}
@Override
public void installDefaults() {
super.installDefaults();
// use heavy-weight popups on macOS to get nice drop shadow from OS
if( SystemInfo.IS_MAC ) {
oldLightWeightPopupEnabled = popupMenu.isLightWeightPopupEnabled();
popupMenu.setLightWeightPopupEnabled( false );
}
}
@Override
protected void uninstallDefaults() {
super.uninstallDefaults();
if( SystemInfo.IS_MAC )
popupMenu.setLightWeightPopupEnabled( oldLightWeightPopupEnabled );
}
}