classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Added Scrollable impl to javax.swing.text.JTextCompone


From: Roman Kennke
Subject: [cp-patches] FYI: Added Scrollable impl to javax.swing.text.JTextComponent
Date: Mon, 23 May 2005 16:27:59 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

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

2005-05-23  Roman Kennke  <address@hidden>

       * 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"
+                                         );
   }
 
   /**

reply via email to

[Prev in Thread] Current Thread [Next in Thread]