if (getScrollableTracksViewportWidth()) pref.width = getUI().getMinimumSize(this).width; if (getScrollableTracksViewportHeight()) pref.height = getUI().getMinimumSize(this).height;
Container parent = getParent(); if (parent instanceof JViewport) { JViewport vp = (JViewport) getParent(); TextUI ui = getUI(); Dimension min = null; if (! getScrollableTracksViewportWidth()) { min = ui.getMinimumSize(this); int vpWidth = vp.getWidth(); if (vpWidth != 0 && vpWidth < min.width) pref.width = min.width; } if (! getScrollableTracksViewportHeight()) { if (min == null) min = ui.getMinimumSize(this); int vpHeight = vp.getHeight(); if (vpHeight != 0 && vpHeight < min.height) pref.height = min.height; } }
    public Dimension getPreferredSize()    {    Dimension pref = super.getPreferredSize();    if (getScrollableTracksViewportWidth())      pref.width = getUI().getMinimumSize(this).width;    if (getScrollableTracksViewportHeight())      pref.height = getUI().getMinimumSize(this).height;    return pref;    }