diff options
author | Tania Bento <tbento@redhat.com> | 2006-12-08 16:49:35 +0000 |
---|---|---|
committer | Tania Bento <tbento@redhat.com> | 2006-12-08 16:49:35 +0000 |
commit | 24bb46e990e91b4cc22795c39990862c7a6aa3b6 (patch) | |
tree | 3e35242e290907afcfce9994ab1c271e0a81206c /java/awt | |
parent | a4ef9620e22209ba431ca8bb3aaf0e73b4742426 (diff) | |
download | classpath-24bb46e990e91b4cc22795c39990862c7a6aa3b6.tar.gz |
2006-12-08 Tania Bento <tbento@redhat.com>
* java/awt/ScrollPane.java
(getScrollPosition): Throw NullPointerException if scrollpane
does have a child.
(setScrollPosition(int, int)): Throw NullPointerException if
scrollpane does have a child. Check that both ints are within
the allowed bounds; If they are not, scroll to the closest allowed
bound.
Diffstat (limited to 'java/awt')
-rw-r--r-- | java/awt/ScrollPane.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/java/awt/ScrollPane.java b/java/awt/ScrollPane.java index 35a81300d..100a17b6a 100644 --- a/java/awt/ScrollPane.java +++ b/java/awt/ScrollPane.java @@ -338,10 +338,15 @@ getVScrollbarWidth() * Returns the current scroll position of the viewport. * * @return The current scroll position of the viewport. + * + * @throws NullPointerException if the scrollpane does have a child. */ public Point getScrollPosition() { + if (getComponentCount() == 0) + throw new NullPointerException(); + int x = 0; int y = 0; @@ -380,20 +385,35 @@ setScrollPosition(Point scrollPosition) throws IllegalArgumentException * @param x The new X coordinate of the scroll position. * @param y The new Y coordinate of the scroll position. * + * @throws NullPointerException if scrollpane does not have a child. + * * @exception IllegalArgumentException If the specified value is outside * the legal scrolling range. */ public void setScrollPosition(int x, int y) { + if (getComponentCount() == 0) + throw new NullPointerException("child is null"); + + if (x > (int) (getComponent(0).getWidth() - getViewportSize().getWidth())) + x = (int) (getComponent(0).getWidth() - getViewportSize().getWidth()); + if (y > (int) (getComponent(0).getHeight() - getViewportSize().getHeight())) + y = (int) (getComponent(0).getHeight() - getViewportSize().getHeight()); + + if (x < 0) + x = 0; + if (y < 0) + y = 0; + Adjustable h = getHAdjustable(); Adjustable v = getVAdjustable(); - + if (h != null) h.setValue(x); if (v != null) v.setValue(y); - + ScrollPanePeer spp = (ScrollPanePeer)getPeer(); if (spp != null) spp.setScrollPosition(x, y); |