void (@NotNull ID window) { ID tabGroup = Foundation.invoke(window, "tabGroup"); if (!ID.NIL.equals(Foundation.invoke(tabGroup, "observationInfo"))) { return; } if (myObserverDelegate == null) { myObserverCallback = new Callback() { @SuppressWarnings("unused") public void callback(ID self, Pointer selector, ID keyPath, ID ofObject, ID change, Pointer context) { ApplicationManager.getApplication().invokeLater(() -> updateTabBars(null)); } }; ID delegateClass = Foundation.allocateObjcClassPair(Foundation.getObjcClass("NSObject"), "MyWindowTabGroupObserver"); Foundation.addMethod(delegateClass, Foundation.createSelector("observeValueForKeyPath:ofObject:change:context:"), myObserverCallback, "v*"); Foundation.registerObjcClassPair(delegateClass); myObserverDelegate = Foundation.invoke("MyWindowTabGroupObserver", "new"); } Foundation.invoke(tabGroup, "addObserver:forKeyPath:options:context:", myObserverDelegate, Foundation.nsString("windows"), 0, ID.NIL); }