void () { // Called on AppKit when the menu opening myIsOpened = true; if (myOnOpen == null) { return; } myOpenTimeMs = System.currentTimeMillis(); if (USE_STUB) { // NOTE: must add stub item when the menu opens (otherwise AppKit considers it as empty, and we can't fill it later) MenuItem stub = new MenuItem(); myItems.add(stub); stub.isInHierarchy = true; ensureNativePeer(); stub.ensureNativePeer(); nativeAddItem(nativePeer, stub.nativePeer, false/*already on AppKit thread*/); ApplicationManager.getApplication().invokeLater(() -> { beginFill(); myOnOpen.run(); endFill(true); }); } else { beginFill(); invokeWithLWCToolkit(myOnOpen, myComponent, true); endFill(false/*already on AppKit thread*/); } }