summaryrefslogtreecommitdiff
path: root/javax/swing/ScrollPaneLayout.java
diff options
context:
space:
mode:
Diffstat (limited to 'javax/swing/ScrollPaneLayout.java')
-rw-r--r--javax/swing/ScrollPaneLayout.java127
1 files changed, 78 insertions, 49 deletions
diff --git a/javax/swing/ScrollPaneLayout.java b/javax/swing/ScrollPaneLayout.java
index a249c2773..5e51e1895 100644
--- a/javax/swing/ScrollPaneLayout.java
+++ b/javax/swing/ScrollPaneLayout.java
@@ -44,6 +44,7 @@ import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
+import java.awt.Point;
import java.io.Serializable;
import javax.swing.border.Border;
@@ -197,9 +198,27 @@ public class ScrollPaneLayout
return null;
}
+ private static void maybeSetPreferredSize(JComponent src, Dimension dim)
+ {
+ Dimension tmp = null;
+ if (src != null)
+ tmp = src.getPreferredSize();
+ if (tmp != null)
+ dim.setSize(tmp);
+ }
+
+ private static void maybeSetMinimumSize(JComponent src, Dimension dim)
+ {
+ Dimension tmp = null;
+ if (src != null)
+ tmp = src.getMinimumSize();
+ if (tmp != null)
+ dim.setSize(tmp);
+ }
+
public Dimension preferredLayoutSize(Container parent)
{
- if (parent instanceof JScrollPane)
+ if (parent != null && parent instanceof JScrollPane)
{
JScrollPane sc = (JScrollPane) parent;
synchronized (sc.getTreeLock ())
@@ -217,36 +236,38 @@ public class ScrollPaneLayout
Insets viewportInsets = null;
if (viewportBorder != null)
+ {
viewportInsets = viewportBorder.getBorderInsets(parent);
+ if (viewportInsets != null)
+ viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,
+ viewportInsets.top + viewportInsets.bottom);
+ }
if (insets != null)
insetsSize.setSize(insets.left + insets.right,
insets.top + insets.bottom);
if (viewport != null)
- viewportSize.setSize(viewport.getPreferredSize());
-
- if (colHead != null)
- columnHeaderSize.setSize(colHead.getPreferredSize());
-
- if (rowHead != null)
- rowHeaderSize.setSize(rowHead.getPreferredSize());
-
- if (vsb != null)
- verticalScrollBarSize.setSize(vsb.getPreferredSize());
-
- if (hsb != null)
- horizontalScrollBarSize.setSize(hsb.getPreferredSize());
-
- /*
- System.err.println("widths: [vp=" + viewportSize.width +
- ", h=" + columnHeaderSize.width +
- ", sc=" + horizontalScrollBarSize.width + "]");
-
- System.err.println("heights: [vp=" + viewportSize.height +
- ", h=" + rowHeaderSize.height +
- ", sc=" + verticalScrollBarSize.height + "]");
- */
+ {
+ Component view = null;
+ Scrollable scr = null;
+ Dimension pref = null;
+
+ view = viewport.getView();
+ if (view != null && view instanceof Scrollable)
+ scr = (Scrollable) view;
+ if (scr != null)
+ pref = scr.getPreferredScrollableViewportSize();
+ if (pref == null)
+ pref = viewport.getPreferredSize();
+ if (pref != null)
+ viewportSize.setSize(pref);
+ }
+
+ maybeSetPreferredSize(colHead, columnHeaderSize);
+ maybeSetPreferredSize(rowHead, rowHeaderSize);
+ maybeSetPreferredSize(vsb, verticalScrollBarSize);
+ maybeSetPreferredSize(hsb, horizontalScrollBarSize);
return new Dimension(insetsSize.width
+ viewportSize.width
@@ -286,28 +307,26 @@ public class ScrollPaneLayout
Insets viewportInsets = null;
if (viewportBorder != null)
+ {
viewportInsets = viewportBorder.getBorderInsets(parent);
+ if (viewportInsets != null)
+ viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,
+ viewportInsets.top + viewportInsets.bottom);
+ }
if (insets != null)
insetsSize.setSize(insets.left + insets.right,
insets.top + insets.bottom);
- if (viewport != null)
- viewportSize.setSize(viewport.getMinimumSize());
-
- if (colHead != null)
- columnHeaderSize.setSize(colHead.getMinimumSize());
-
- if (rowHead != null)
- rowHeaderSize.setSize(rowHead.getMinimumSize());
+ maybeSetMinimumSize(viewport, viewportSize);
+ maybeSetMinimumSize(colHead, columnHeaderSize);
+ maybeSetMinimumSize(rowHead, rowHeaderSize);
- if (vsb != null
- && vsbPolicy != VERTICAL_SCROLLBAR_NEVER)
- verticalScrollBarSize.setSize(vsb.getMinimumSize());
+ if (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)
+ maybeSetMinimumSize(vsb, verticalScrollBarSize);
- if (hsb != null
- && hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)
- horizontalScrollBarSize.setSize(hsb.getMinimumSize());
+ if (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)
+ maybeSetMinimumSize(hsb, horizontalScrollBarSize);
return new Dimension(insetsSize.width
+ viewportSize.width
@@ -355,14 +374,15 @@ public class ScrollPaneLayout
JScrollPane sc = (JScrollPane) parent;
synchronized (sc.getTreeLock ())
{
- Rectangle scrollPaneBounds = sc.getBounds();
JViewport viewport = sc.getViewport();
- Dimension viewportSize = viewport.getSize();
- Dimension viewSize = viewport.getView().getSize();
+ Dimension viewSize = viewport.getViewSize();
+ Point viewPos = viewport.getViewPosition();
int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
+ Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
+
x1 = scrollPaneBounds.x;
y1 = scrollPaneBounds.y;
x4 = scrollPaneBounds.x + scrollPaneBounds.width;
@@ -381,26 +401,25 @@ public class ScrollPaneLayout
int vsbPolicy = sc.getVerticalScrollBarPolicy();
int hsbPolicy = sc.getHorizontalScrollBarPolicy();
+ x3 = x4 - vsb.getPreferredSize().width;
+ y3 = y4 - hsb.getPreferredSize().height;
+
boolean showVsb =
(vsb != null)
&& ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
|| (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
- && viewSize.height > viewportSize.height));
+ && viewSize.height > (y3 - y2)));
boolean showHsb =
(hsb != null)
&& ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
|| (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
- && viewSize.width > viewportSize.width));
+ && viewSize.width > (x3 - x2)));
- if (showVsb)
- x3 = x4 - vsb.getPreferredSize().width;
- else
+ if (!showVsb)
x3 = x4;
- if (showHsb)
- y3 = y4 - hsb.getPreferredSize().height;
- else
+ if (!showHsb)
y3 = y4;
// now set the layout
@@ -415,10 +434,20 @@ public class ScrollPaneLayout
rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2));
if (showVsb)
+ {
+ vsb.setVisible(true);
vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2));
+ }
+ else if (vsb != null)
+ vsb.setVisible(false);
if (showHsb)
+ {
+ hsb.setVisible(true);
hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3));
+ }
+ else if (hsb != null)
+ hsb.setVisible(false);
if (upperLeft != null)
upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1));