JViewport viewport = (JViewport) parent;
for (int i = 0; i < cellHeights.length; i++) maxCellHeight = Math.max(maxCellHeight, cellHeights[i]); }
  public Dimension getPreferredSize(JComponent c)  {    int size = list.getModel().getSize();    if (size == 0)      return new Dimension(0, 0);    int visibleRows = list.getVisibleRowCount();    int layoutOrientation = list.getLayoutOrientation();    Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);    Dimension retVal = bounds.getSize();    Component parent = list.getParent();    if ((visibleRows == -1) && (parent instanceof JViewport))      {        JViewport viewport = (JViewport) parent;        if (layoutOrientation == JList.HORIZONTAL_WRAP)          {            int h = viewport.getSize().height;            int cellsPerCol = h / cellHeight;            int w = size / cellsPerCol * cellWidth;            retVal = new Dimension(w, h);          }        else if (layoutOrientation == JList.VERTICAL_WRAP)          {            int w = viewport.getSize().width;            int cellsPerRow = Math.max(w / cellWidth, 1);            int h = size / cellsPerRow * cellHeight;            retVal = new Dimension(w, h);          }      }    return retVal;  }