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

@@ -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 );
}
}