I added two methods in order to improve Scrollable behaviour of JTextArea.
2005-05-23 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/JTextArea.java (getPreferredScrollableViewportSize): Added and implemented new method. (getScrollableUnitIncrement): Added and implemented new method. /Roman
Index: javax/swing/JTextArea.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JTextArea.java,v retrieving revision 1.10 diff -u -r1.10 JTextArea.java --- javax/swing/JTextArea.java 28 Apr 2005 05:46:01 -0000 1.10 +++ javax/swing/JTextArea.java 23 May 2005 14:06:38 -0000 @@ -38,7 +38,9 @@ package javax.swing; +import java.awt.Dimension; import java.awt.FontMetrics; +import java.awt.Rectangle; import javax.swing.text.BadLocationException; import javax.swing.text.Document; @@ -230,6 +232,55 @@ } /** + * Returns the increment that is needed to expose exactly one new line + * of text. This is implemented here to return the values of + * [EMAIL PROTECTED] #getRowHeight} and [EMAIL PROTECTED] getColumnWidth}, depending on + * the value of the argument <code>direction</code>. + * + * @param visibleRect the view area that is visible in the viewport + * @param orientation either [EMAIL PROTECTED] SwingConstants.VERTICAL} or + * [EMAIL PROTECTED] SwingConstants.HORIZONTAL} + * @param direction less than zero for up/left scrolling, greater + * than zero for down/right scrolling + * + * @return the increment that is needed to expose exactly one new row + * or column of text + * + * @throws IllegalArgumentException if <code>orientation</code> is invalid + */ + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, + int direction) + { + if (orientation == SwingConstants.VERTICAL) + return getRowHeight(); + else if (orientation == SwingConstants.HORIZONTAL) + return getColumnWidth(); + else + throw new IllegalArgumentException("orientation must be either " + + "javax.swing.SwingConstants.VERTICAL " + + "or " + + "javax.swing.SwingConstants.HORIZONTAL" + ); + } + + /** + * Returns the preferred size of that text component in the case + * it is embedded within a JScrollPane. This uses the column and + * row settings if they are explicitly set, or fall back to + * the superclass's behaviour. + * + * @return the preferred size of that text component in the case + * it is embedded within a JScrollPane + */ + public Dimension getPreferredScrollableViewportSize() + { + if ((rows > 0) && (columns > 0)) + return new Dimension(columns * getColumnWidth(), rows * getRowHeight()); + else + return super.getPreferredScrollableViewportSize(); + } + + /** * Returns the UI class ID string. * * @return the string "TextAreaUI"
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches