Index: javax/swing/JList.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v retrieving revision 1.30 diff -u -r1.30 JList.java --- javax/swing/JList.java 17 Aug 2005 18:43:37 -0000 1.30 +++ javax/swing/JList.java 2 Sep 2005 16:06:05 -0000 @@ -1032,20 +1032,41 @@ */ public Dimension getPreferredScrollableViewportSize() { + //If the layout orientation is not VERTICAL, then this will + //return the value from getPreferredSize. The current ListUI is + //expected to override getPreferredSize to return an appropriate value. + if (getLayoutOrientation() != VERTICAL) + return getPreferredSize(); + + if (fixedCellHeight != -1 && fixedCellWidth != -1) + return new Dimension(fixedCellWidth, getModel().getSize() * + fixedCellHeight); - Dimension retVal = getPreferredSize(); - if (getLayoutOrientation() == VERTICAL) + int prefWidth, prefHeight; + if (fixedCellWidth != -1) + prefWidth = fixedCellWidth; + else { - if (fixedCellHeight != -1) - { - if (fixedCellWidth != -1) - { - int size = getModel().getSize(); - retVal = new Dimension(fixedCellWidth, size * fixedCellHeight); - } // TODO: add else clause (preferredSize is ok for now) - } // TODO: add else clause (preferredSize is ok for now) + prefWidth = 0; + int size = getModel().getSize(); + for (int i = 0; i < size; i++) + if (getCellBounds(i, i).width > prefWidth) + prefWidth = getCellBounds(i, i).width; } - return retVal; + + if (getModel().getSize() == 0 && fixedCellWidth == -1) + return new Dimension(256, 16 * getVisibleRowCount()); + else if (getModel().getSize() == 0) + return new Dimension (fixedCellWidth, 16 * getVisibleRowCount()); + + if (fixedCellHeight != -1) + prefHeight = fixedCellHeight; + else + { + prefHeight = getVisibleRowCount() * getCellBounds + (getFirstVisibleIndex(), getFirstVisibleIndex()).height; + } + return new Dimension (prefWidth, prefHeight); } /**