Skip to content

Commit

Permalink
PopupMenu: PopupMenus with no component shouldn't be displayed.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Aug 6, 2021
1 parent b6f7973 commit b72f069
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.logging.Logger;

import javax.swing.*;
import javax.swing.plaf.RootPaneUI;

import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.properties.uiresource.DarkColorUIResource;
Expand All @@ -51,6 +50,10 @@ public class DarkPopupFactory extends PopupFactory {

private HeavyWeightParent heavyWeightParent;

public static Popup createNoOpPopup() {
return new NoOpPopup();
}

@Override
public Popup getPopup(final Component owner, final Component contents, final int x, final int y)
throws IllegalArgumentException {
Expand Down Expand Up @@ -308,38 +311,11 @@ public enum PopupType {
HEAVY_WEIGHT
}

private static class WrapperRootPane extends JRootPane implements RootPaneContainer {

@Override
public void updateUI() {
setUI(new RootPaneUI() {});
}

private static class NoOpPopup extends Popup {
@Override
public boolean isOpaque() {
return false;
}
public void show() {}

@Override
public JRootPane getRootPane() {
return this;
}

@Override
protected void paintComponent(final Graphics g) {}

@Override
public void doLayout() {
int w = getWidth();
int h = getHeight();
layout(getLayeredPane(), w, h);
layout(getGlassPane(), w, h);
layout(getContentPane(), w, h);
}

private void layout(final Component c, final int w, final int h) {
c.setBounds(0, 0, w, h);
c.doLayout();
}
public void hide() {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ private Dimension getConstraintSizes(final JComponent popup, final Point pos) {

@Override
public Popup getPopup(final JPopupMenu popup, final int x, final int y) {
if (popup.getComponentCount() == 0) {
return DarkPopupFactory.createNoOpPopup();
}
PopupMenuContainer container = getPopupMenuContainer();
if (container == null) return super.getPopup(popup, x, y);
Dimension constraintSize = getConstraintSizes(popup, new Point(x, y));
Expand Down

0 comments on commit b72f069

Please sign in to comment.