summaryrefslogtreecommitdiffstats
path: root/libjava/javax/swing/JList.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/swing/JList.java')
-rw-r--r--libjava/javax/swing/JList.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/libjava/javax/swing/JList.java b/libjava/javax/swing/JList.java
index 732a0c077a0..937d41cceac 100644
--- a/libjava/javax/swing/JList.java
+++ b/libjava/javax/swing/JList.java
@@ -994,7 +994,32 @@ public class JList extends JComponent implements Accessible, Scrollable
*/
public Dimension getPreferredScrollableViewportSize()
{
- return getPreferredSize();
+ int vis = getVisibleRowCount();
+ int nrows = getModel() == null ? 0 : getModel().getSize();
+ // FIXME: this is a somewhat arbitrary default, but.. ?
+ Dimension single = new Dimension(10, 10);;
+ Rectangle bounds = null;
+
+ if (vis > nrows)
+ {
+ if (fixedCellWidth != -1 &&
+ fixedCellHeight != -1)
+ {
+ single = new Dimension(fixedCellWidth, fixedCellHeight);
+ }
+ else if (nrows != 0 && getUI() != null)
+ {
+ Rectangle tmp = getUI().getCellBounds(this, 0, 0);
+ if (tmp != null)
+ single = tmp.getSize();
+ }
+ }
+ else if (getUI() != null)
+ {
+ return getUI().getCellBounds(this, 0, vis - 1).getSize();
+ }
+
+ return new Dimension(single.width, single.height * vis);
}
/**
OpenPOWER on IntegriCloud