Dimension () { if (isPreferredSizeSet()) return super.getPreferredSize(); // do not violate Swing's contract final int dividerWidth = getDividerWidth(); if (myFirstComponent != null && myFirstComponent.isVisible() && mySecondComponent != null && mySecondComponent.isVisible()) { final Dimension firstPrefSize = unwrap(myFirstComponent).getPreferredSize(); final Dimension secondPrefSize = unwrap(mySecondComponent).getPreferredSize(); if (myDividerPositionStrategy == DividerPositionStrategy.DISTRIBUTE) { Dimension firstMinSize = unwrap(myFirstComponent).getMinimumSize(); Dimension secondMinSize = unwrap(mySecondComponent).getMinimumSize(); firstPrefSize.width = Math.max(firstMinSize.width, firstPrefSize.width); firstPrefSize.height = Math.max(firstMinSize.height, firstPrefSize.height); secondPrefSize.width = Math.max(secondMinSize.width, secondPrefSize.width); secondPrefSize.height = Math.max(secondMinSize.height, secondPrefSize.height); } return isVertical() ? new Dimension(Math.max(firstPrefSize.width, secondPrefSize.width), firstPrefSize.height + dividerWidth + secondPrefSize.height) : new Dimension(firstPrefSize.width + dividerWidth + secondPrefSize.width, Math.max(firstPrefSize.height, secondPrefSize.height)); } if (myFirstComponent != null && myFirstComponent.isVisible()) { // only first component is visible return myFirstComponent.getPreferredSize(); } if (mySecondComponent != null && mySecondComponent.isVisible()) { // only second component is visible return mySecondComponent.getPreferredSize(); } return super.getPreferredSize(); }