Dimension (Container parent, boolean vertical, Function<? super Component, ? extends Dimension> getSize) { int[] extraSize = new int[2]; JComponent jParent = (JComponent)parent; getSize(jParent, LightToolWindow.LEFT_MIN_KEY, vertical, extraSize); getSize(jParent, LightToolWindow.RIGHT_MIN_KEY, vertical, extraSize); Component toolbar = parent.getComponent(0); Dimension toolbarSize = toolbar.isVisible() ? getSize.fun(toolbar) : new Dimension(); Dimension contentSize = getSize.fun(parent.getComponent(1)); return new Dimension(Math.max(toolbarSize.width, contentSize.width + extraSize[0]), toolbarSize.height + contentSize.height + extraSize[1]); }