void () { if (myAdjustWindow) { Window window = SwingUtilities.getWindowAncestor(myPanel); if (window != null) { Dimension contentSize = myPreviousContentSize; if (contentSize == null || contentSize.width <= 0 || contentSize.height <= 0) { contentSize = myContent.getPreferredSize(); } Dimension size = window.getSize(), newSize; if (myOn) { newSize = new Dimension(Math.max(size.width, myContent.getSize().width), size.height + contentSize.height); } else { newSize = new Dimension(size.width, size.height - contentSize.height); } if (!newSize.equals(size)) { UIUtil.invokeLaterIfNeeded(() -> { if (window.isShowing()) { window.setSize(newSize); } }); } } } }