author | sveerabhadra |
Thu, 08 Mar 2018 14:31:54 +0530 | |
changeset 49227 | 96bebffe0be1 |
permissions | -rw-r--r-- |
49227
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
1 |
/* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
4 |
* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
8 |
* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
13 |
* accompanied this code). |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
14 |
* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
18 |
* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
21 |
* questions. |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
22 |
*/ |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
23 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
24 |
/* |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
25 |
* @test |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
26 |
* @key headful |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
27 |
* @bug 8195738 |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
28 |
* @summary scroll position in ScrollPane is reset after calling validate() |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
29 |
* @run main ScrollPaneValidateTest |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
30 |
*/ |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
31 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
32 |
import java.awt.ScrollPane; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
33 |
import java.awt.BorderLayout; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
34 |
import java.awt.GridLayout; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
35 |
import java.awt.Button; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
36 |
import java.awt.Dimension; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
37 |
import java.awt.Frame; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
38 |
import java.awt.Panel; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
39 |
import java.awt.Point; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
40 |
import java.awt.Robot; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
41 |
import java.awt.AWTException; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
42 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
43 |
public class ScrollPaneValidateTest extends Frame { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
44 |
ScrollPane pane; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
45 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
46 |
public ScrollPaneValidateTest() { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
47 |
setBounds(300, 300, 300, 300); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
48 |
pane = new ScrollPane(ScrollPane.SCROLLBARS_NEVER); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
49 |
add(pane, BorderLayout.NORTH); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
50 |
pane.add(new InnerPanel()); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
51 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
52 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws AWTException { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
54 |
Robot robot = new Robot(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
55 |
final ScrollPaneValidateTest obj = new ScrollPaneValidateTest(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
56 |
obj.setVisible(true); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
57 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
58 |
// set to some scroll position |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
59 |
obj.pane.setScrollPosition(600, 200); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
60 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
61 |
// get the newly set position |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
62 |
Point scrollPosition = obj.pane.getScrollPosition(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
63 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
64 |
// call validate multiple times |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
65 |
obj.pane.validate(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
66 |
robot.delay(1000); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
67 |
obj.pane.validate(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
68 |
robot.delay(1000); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
69 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
70 |
// compare position after calling the validate function |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
71 |
if(!scrollPosition.equals(obj.pane.getScrollPosition())) { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
72 |
obj.dispose(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
73 |
throw new RuntimeException("Scrolling position is changed in ScrollPane"); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
74 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
75 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
76 |
obj.dispose(); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
77 |
return; |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
78 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
79 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
80 |
class InnerPanel extends Panel { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
81 |
public InnerPanel() { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
82 |
this.setLayout(new GridLayout(2, 4)); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
83 |
for (int i = 1; i <= 8; i++) { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
84 |
this.add(new Button("Button" + i)); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
85 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
86 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
87 |
|
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
88 |
public Dimension getPreferredSize() { |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
89 |
return new Dimension(980, 200); |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
90 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
91 |
} |
96bebffe0be1
8195738: scroll poistion in ScrollPane is reset after calling validate()
sveerabhadra
parents:
diff
changeset
|
92 |
} |