I added 3 method implementations that should improve behaviour of text components inside JScrollPanes.

2005-05-23  Roman Kennke  <[EMAIL PROTECTED]>

       * javax/swing/text/JTextComponent.java
       (getPreferredScrollableViewportSize): Implemented this method.
       (getScrollableUnitIncrement): Implemented this method.
       (getScrollableBlockIncrement): Implemented this method.

/Roman

Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v
retrieving revision 1.30
diff -u -r1.30 JTextComponent.java
--- javax/swing/text/JTextComponent.java        20 May 2005 19:42:31 -0000      
1.30
+++ javax/swing/text/JTextComponent.java        23 May 2005 14:20:57 -0000
@@ -69,6 +69,7 @@
 import javax.swing.JViewport;
 import javax.swing.KeyStroke;
 import javax.swing.Scrollable;
+import javax.swing.SwingConstants;
 import javax.swing.Timer;
 import javax.swing.TransferHandler;
 import javax.swing.UIManager;
@@ -1130,19 +1131,39 @@
 
   public Dimension getPreferredScrollableViewportSize()
   {
-    return null;
+    return getPreferredSize();
   }
 
   public int getScrollableUnitIncrement(Rectangle visible, int orientation,
                                         int direction)
   {
-    return 0;
+    // We return 1/10 of the visible area as documented in Sun's API docs.
+    if (orientation == SwingConstants.HORIZONTAL)
+      return visible.width / 10;
+    else if (orientation == SwingConstants.VERTICAL)
+      return visible.height / 10;
+    else
+      throw new IllegalArgumentException("orientation must be either "
+                                      + "javax.swing.SwingConstants.VERTICAL "
+                                      + "or "
+                                      + "javax.swing.SwingConstants.HORIZONTAL"
+                                         );
   }
 
   public int getScrollableBlockIncrement(Rectangle visible, int orientation,
                                          int direction)
   {
-    return 0;
+    // We return the whole visible area as documented in Sun's API docs.
+    if (orientation == SwingConstants.HORIZONTAL)
+      return visible.width;
+    else if (orientation == SwingConstants.VERTICAL)
+      return visible.height;
+    else
+      throw new IllegalArgumentException("orientation must be either "
+                                      + "javax.swing.SwingConstants.VERTICAL "
+                                      + "or "
+                                      + "javax.swing.SwingConstants.HORIZONTAL"
+                                         );
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to