Invoker null check

This commit is contained in:
Prasanta Sadhukhan 2026-01-27 09:44:39 +00:00
parent c78ede2731
commit 91151bce29
2 changed files with 13 additions and 12 deletions

View File

@ -952,20 +952,21 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
@BeanProperty(bound = false, expert = true, description @BeanProperty(bound = false, expert = true, description
= "The invoking component for the popup menu") = "The invoking component for the popup menu")
public void setInvoker(Component invoker) { public void setInvoker(Component invoker) {
if (invoker != null) { Component oldInvoker = this.invoker;
Component oldInvoker = this.invoker; this.invoker = invoker;
this.invoker = invoker;
if ((oldInvoker != this.invoker) && (ui != null)) { if ((oldInvoker != this.invoker) && (ui != null)) {
ui.uninstallUI(this); ui.uninstallUI(this);
if (oldInvoker != null) { if (oldInvoker != null) {
oldInvoker.removePropertyChangeListener("ancestor", propListener); oldInvoker.removePropertyChangeListener("ancestor", propListener);
}
invoker.addPropertyChangeListener("ancestor", propListener);
ui.installUI(this);
} }
invalidate(); if (invoker != null) {
invoker.addPropertyChangeListener("ancestor", propListener);
}
ui.installUI(this);
} }
invalidate();
} }
/** /**

View File

@ -73,6 +73,7 @@ public class TestPopupInvoker {
@Override @Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
popupHidden.countDown(); popupHidden.countDown();
popupMenu.setInvoker(null);
} }
@Override @Override
@ -108,7 +109,6 @@ public class TestPopupInvoker {
} }
} finally { } finally {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
popupMenu.setInvoker(null);
if (frame != null) { if (frame != null) {
frame.dispose(); frame.dispose();
} }