private Dimension getPreferredSize(Container parent, int maxWidth) {

		if (maxWidth == 0) {
			return getPreferredSize(parent);
		}
		Insets insets = parent.getInsets();
		int n = parent.getComponentCount();

		if (n <= 0) {
			return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
		}

		int horizontalInsets = insets.left + insets.right;
		int verticalInsets = insets.top + insets.bottom;

		Dimension standardSize = computeStandardComponentSize(parent);
		Component c = parent.getComponent(0);
		Dimension preferredSize = getPreferredDimensionForComponent(c, standardSize);

		int rowWidth = preferredSize.width;
		int rowHeight = getStandardComponentHeight(parent);
		int height = rowHeight;
		int availableWidth = maxWidth - horizontalInsets;

		for (int i = 1; i < n; i++) {
			c = parent.getComponent(i);
			preferredSize = getPreferredDimensionForComponent(c, standardSize);

			// if we still have room on this line
			if (rowWidth + hgap + preferredSize.width <= availableWidth) {
				rowWidth += preferredSize.width + hgap;
			}
			else {
				height += rowHeight + vgap;
				rowWidth = preferredSize.width;
			}
		}

		return new Dimension(availableWidth + horizontalInsets, height + verticalInsets);
	}
@see javax.swing.Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
Ghidra/Framework/Docking/src/main/java/docking/widgets/VariableHeightPanel.java