Dimension (Component view) { if (view instanceof JList) return getPreferredScrollableViewportSize((JList)view); if (view instanceof JTree) return getPreferredScrollableViewportSize((JTree)view); if (view instanceof Scrollable) return ((Scrollable)view).getPreferredScrollableViewportSize(); if (view instanceof JComponent) return getPreferredSizeWithoutScrollBars((JComponent)view); return view == null ? null : view.getPreferredSize(); }