if (list.getLayoutOrientation() == JList.VERTICAL) cellWidth = Math.max(cellWidth, list.getSize().width);
  protected void updateLayoutState()  {    int nrows = list.getModel().getSize();    cellHeight = -1;    cellWidth = -1;    if (cellHeights == null || cellHeights.length != nrows)      cellHeights = new int[nrows];        ListCellRenderer rend = list.getCellRenderer();    // Update the cellHeight(s) fields.    int fixedCellHeight = list.getFixedCellHeight();    if (fixedCellHeight > 0)      {        cellHeight = fixedCellHeight;        cellHeights = null;      }    else      {        cellHeight = -1;        for (int i = 0; i < nrows; ++i)          {            Component flyweight =              rend.getListCellRendererComponent(list,                      list.getModel().getElementAt(i),                      i, list.isSelectedIndex(i),                      list.getSelectionModel().getAnchorSelectionIndex() == i);            Dimension dim = flyweight.getPreferredSize();            cellHeights[i] = dim.height;          }      }    // Update the cellWidth field.    int fixedCellWidth = list.getFixedCellWidth();    if (fixedCellWidth > 0)      cellWidth = fixedCellWidth;    else      {        for (int i = 0; i < nrows; ++i)          {            Component flyweight =              rend.getListCellRendererComponent(list,                                                list.getModel().getElementAt(i),                                                i, list.isSelectedIndex(i),                                                list.getSelectionModel().getAnchorSelectionIndex() == i);            Dimension dim = flyweight.getPreferredSize();            cellWidth = Math.max(cellWidth, dim.width);          }        if (list.getLayoutOrientation() == JList.VERTICAL)          cellWidth = Math.max(cellWidth, list.getSize().width);      }  }