void () { Window window = myPeer.getWindow(); if (window == null) { return; } myResizeListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (!myResizeInProgress) { myActualSize = myPeer.getSize(); if (myErrorText != null && myErrorText.isVisible()) { myActualSize.height -= myErrorText.getMinimumSize().height; } } } }; window.addComponentListener(myResizeListener); Disposer.register(myDisposable, this::disposeResizeListener); }