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
= "The invoking component for the popup menu")
public void setInvoker(Component invoker) {
if (invoker != null) {
Component oldInvoker = this.invoker;
this.invoker = invoker;
Component oldInvoker = this.invoker;
this.invoker = invoker;
if ((oldInvoker != this.invoker) && (ui != null)) {
ui.uninstallUI(this);
if (oldInvoker != null) {
oldInvoker.removePropertyChangeListener("ancestor", propListener);
}
invoker.addPropertyChangeListener("ancestor", propListener);
ui.installUI(this);
if ((oldInvoker != this.invoker) && (ui != null)) {
ui.uninstallUI(this);
if (oldInvoker != null) {
oldInvoker.removePropertyChangeListener("ancestor", propListener);
}
invalidate();
if (invoker != null) {
invoker.addPropertyChangeListener("ancestor", propListener);
}
ui.installUI(this);
}
invalidate();
}
/**

View File

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