diff --git a/src/share/classes/javax/swing/text/DefaultEditorKit.java b/src/share/classes/javax/swing/text/DefaultEditorKit.java
index 32c5c1fda3b2f4b75c6b25ecca58adaffc5685c3..7651b9f2e7db87c55a582a9938882430298bc905 100644
--- a/src/share/classes/javax/swing/text/DefaultEditorKit.java
+++ b/src/share/classes/javax/swing/text/DefaultEditorKit.java
@@ -1461,13 +1461,17 @@ public class DefaultEditorKit extends EditorKit {
// Make sure the new visible location contains
// the location of dot, otherwise Caret will
// cause an additional scroll.
- adjustScrollIfNecessary(target, newVis, initialY,
- newIndex);
- if (select) {
- target.moveCaretPosition(newIndex);
- }
- else {
- target.setCaretPosition(newIndex);
+ int newY = getAdjustedY(target, newVis, newIndex);
+
+ if (direction == -1 && newY <= initialY || direction == 1 && newY >= initialY) {
+ // Change index and correct newVis.y only if won't cause scrolling upward
+ newVis.y = newY;
+
+ if (select) {
+ target.moveCaretPosition(newIndex);
+ } else {
+ target.setCaretPosition(newIndex);
+ }
}
}
} catch (BadLocationException ble) { }
@@ -1513,34 +1517,27 @@ public class DefaultEditorKit extends EditorKit {
}
/**
- * Adjusts the rectangle that indicates the location to scroll to
+ * Returns adjustsed {@code y} position that indicates the location to scroll to
* after selecting index
.
*/
- private void adjustScrollIfNecessary(JTextComponent text,
- Rectangle visible, int initialY,
- int index) {
+ private int getAdjustedY(JTextComponent text, Rectangle visible, int index) {
+ int result = visible.y;
+
try {
Rectangle dotBounds = text.modelToView(index);
- if (dotBounds.y < visible.y ||
- (dotBounds.y > (visible.y + visible.height)) ||
- (dotBounds.y + dotBounds.height) >
- (visible.y + visible.height)) {
- int y;
-
- if (dotBounds.y < visible.y) {
- y = dotBounds.y;
- }
- else {
- y = dotBounds.y + dotBounds.height - visible.height;
- }
- if ((direction == -1 && y < initialY) ||
- (direction == 1 && y > initialY)) {
- // Only adjust if won't cause scrolling upward.
- visible.y = y;
+ if (dotBounds.y < visible.y) {
+ result = dotBounds.y;
+ } else {
+ if ((dotBounds.y > visible.y + visible.height) ||
+ (dotBounds.y + dotBounds.height > visible.y + visible.height)) {
+ result = dotBounds.y + dotBounds.height - visible.height;
}
}
- } catch (BadLocationException ble) {}
+ } catch (BadLocationException ble) {
+ }
+
+ return result;
}
/**
diff --git a/test/javax/swing/JEditorPane/6917744/bug6917744.java b/test/javax/swing/JEditorPane/6917744/bug6917744.java
new file mode 100644
index 0000000000000000000000000000000000000000..553213d23fd6faaecb58194858384ef1a00ac6fc
--- /dev/null
+++ b/test/javax/swing/JEditorPane/6917744/bug6917744.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6917744
+ * @summary JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
+ * @author Pavel Porvatov
+ * @run main bug6917744
+ */
+
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.io.IOException;
+import javax.swing.*;
+
+import sun.awt.SunToolkit;
+
+public class bug6917744 {
+ private static JFrame frame;
+
+ private static JEditorPane editorPane;
+
+ private static JScrollPane scrollPane;
+
+ private static Robot robot;
+
+ public static void main(String[] args) throws Exception {
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+ robot = new Robot();
+ robot.setAutoDelay(100);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame = new JFrame();
+
+ editorPane = new JEditorPane();
+
+ try {
+ editorPane.setPage(bug6917744.class.getResource("/test.html"));
+ } catch (IOException e) {
+ throw new RuntimeException("HTML resource not found", e);
+ }
+
+ scrollPane = new JScrollPane(editorPane);
+
+ frame.getContentPane().add(scrollPane);
+ frame.setSize(400, 300);
+ frame.setVisible(true);
+ }
+ });
+
+ toolkit.realSync();
+
+ for (int i = 0; i < 50; i++) {
+ robot.keyPress(KeyEvent.VK_PAGE_DOWN);
+ }
+
+ toolkit.realSync();
+
+ // Check that we at the end of document
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
+
+ if (model.getValue() + model.getExtent() != model.getMaximum()) {
+ throw new RuntimeException("Invalid HTML position");
+ }
+ }
+ });
+
+ toolkit.realSync();
+
+ for (int i = 0; i < 50; i++) {
+ robot.keyPress(KeyEvent.VK_PAGE_UP);
+ }
+
+ toolkit.realSync();
+
+ // Check that we at the begin of document
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
+
+ if (model.getValue() != model.getMinimum()) {
+ throw new RuntimeException("Invalid HTML position");
+ }
+
+ frame.dispose();
+ }
+ });
+ }
+}
diff --git a/test/javax/swing/JEditorPane/6917744/test.html b/test/javax/swing/JEditorPane/6917744/test.html
new file mode 100644
index 0000000000000000000000000000000000000000..7532c9e9e156c4b28dc2eb3b7c169aac894aceab
--- /dev/null
+++ b/test/javax/swing/JEditorPane/6917744/test.html
@@ -0,0 +1,494 @@
+
+
+ |
+
+
+ TEST FOR JScrollPane BUG + + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + +This is a test html file. + + + END OF TEST FOR JScrollPane BUG + + + |
++ |