Fixed some problems with JList.getPreferredScrollableViewportSize that
fixed bug 17360. However, similar bug 17362 is still open and I'll
start looking into that now, will hopefully fix it by tomorrow.
I also re-committed the ChangeLog after this because I had the wrong
date in the original entry.
2005-10-26 Anthony Balkissoon <[EMAIL PROTECTED]>
* javax/swing/JList.java:
(getPreferredScrollableViewportSize): Use the preferred width instead
of the width of the widest element. This allows us to use the
user-specified preferred width if setPreferredSize was called. Use
the height of the first row, not the first visible row, when
calculating the preferred height. Added comments and made code cleaner
and more readable.
--Tony
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.37
diff -u -r1.37 JList.java
--- javax/swing/JList.java 20 Oct 2005 20:53:14 -0000 1.37
+++ javax/swing/JList.java 26 Oct 2005 19:01:05 -0000
@@ -1780,36 +1780,43 @@
//return the value from getPreferredSize. The current ListUI is
//expected to override getPreferredSize to return an appropriate value.
if (getLayoutOrientation() != VERTICAL)
- return getPreferredSize();
+ return getPreferredSize();
+ int size = getModel().getSize();
+
+ // Trivial case: if fixedCellWidth and fixedCellHeight were set
+ // just use them
if (fixedCellHeight != -1 && fixedCellWidth != -1)
- return new Dimension(fixedCellWidth, getModel().getSize() *
- fixedCellHeight);
+ return new Dimension(fixedCellWidth, size * fixedCellHeight);
+
+ // If the model is empty we use 16 * the number of visible rows
+ // for the height and either fixedCellWidth (if set) or 256
+ // for the width
+ if (size == 0)
+ {
+ if (fixedCellWidth == -1)
+ return new Dimension(256, 16 * getVisibleRowCount());
+ else
+ return new Dimension(fixedCellWidth, 16 * getVisibleRowCount());
+ }
- int prefWidth, prefHeight;
+ // Calculate the width: if fixedCellWidth was set use that, otherwise
+ // use the preferredWidth
+ int prefWidth;
if (fixedCellWidth != -1)
prefWidth = fixedCellWidth;
else
- {
- prefWidth = 0;
- int size = getModel().getSize();
- for (int i = 0; i < size; i++)
- if (getCellBounds(i, i).width > prefWidth)
- prefWidth = getCellBounds(i, i).width;
- }
-
- if (getModel().getSize() == 0 && fixedCellWidth == -1)
- return new Dimension(256, 16 * getVisibleRowCount());
- else if (getModel().getSize() == 0)
- return new Dimension (fixedCellWidth, 16 * getVisibleRowCount());
+ prefWidth = getPreferredSize().width;
+ // Calculate the height: if fixedCellHeight was set use that, otherwise
+ // use the height of the first row multiplied by the number of visible
+ // rows
+ int prefHeight;
if (fixedCellHeight != -1)
prefHeight = fixedCellHeight;
else
- {
- prefHeight = getVisibleRowCount() * getCellBounds
- (getFirstVisibleIndex(), getFirstVisibleIndex()).height;
- }
+ prefHeight = getVisibleRowCount() * getCellBounds(0, 0).height;
+
return new Dimension (prefWidth, prefHeight);
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches