author | rupashka |
Thu, 23 Dec 2010 18:25:35 +0300 | |
changeset 7786 | 1db9d857af81 |
parent 6652 | 482a7a13ef22 |
child 8377 | 7f7a8d6235e0 |
permissions | -rw-r--r-- |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
1 |
/* |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
4 |
* |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
8 |
* |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
13 |
* accompanied this code). |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
14 |
* |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
18 |
* |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
21 |
* questions. |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
22 |
*/ |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
23 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
24 |
/* @test |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
25 |
@bug 6542335 |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
26 |
@summary different behavior on knob of scroll bar between 1.4.2 and 5.0 |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
27 |
@author Alexander Potochkin |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
28 |
@run main bug6542335 |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
29 |
*/ |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
30 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
31 |
import sun.awt.SunToolkit; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
32 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
33 |
import javax.swing.*; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
34 |
import javax.swing.plaf.basic.BasicScrollBarUI; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
35 |
import java.awt.*; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
36 |
import java.awt.event.InputEvent; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
37 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
38 |
public class bug6542335 { |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
39 |
private static JScrollBar sb; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
40 |
private static MyScrollBarUI ui; |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
41 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
42 |
public static void main(String[] args) throws Exception { |
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
43 |
final Robot robot = new Robot(); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
44 |
robot.setAutoDelay(10); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
45 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
46 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
47 |
|
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
48 |
final Rectangle[] thumbBounds = new Rectangle[1]; |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
49 |
|
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
50 |
SwingUtilities.invokeAndWait(new Runnable() { |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
51 |
public void run() { |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
52 |
final JFrame frame = new JFrame("bug6542335"); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
53 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
54 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
55 |
sb = new JScrollBar(0, 0, 1, 0, 1); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
56 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
57 |
ui = new MyScrollBarUI(); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
58 |
sb.setUI(ui); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
59 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
60 |
sb.setPreferredSize(new Dimension(200, 17)); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
61 |
DefaultBoundedRangeModel rangeModel = new DefaultBoundedRangeModel(); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
62 |
rangeModel.setMaximum(100); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
63 |
rangeModel.setMinimum(0); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
64 |
rangeModel.setExtent(50); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
65 |
rangeModel.setValue(50); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
66 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
67 |
sb.setModel(rangeModel); |
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
68 |
frame.add(sb, BorderLayout.NORTH); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
69 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
70 |
frame.setSize(200, 100); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
71 |
frame.setVisible(true); |
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
72 |
|
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
73 |
thumbBounds[0] = new Rectangle(ui.getThumbBounds()); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
74 |
} |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
75 |
}); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
76 |
|
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
77 |
toolkit.realSync(); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
78 |
|
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
79 |
SwingUtilities.invokeAndWait(new Runnable() { |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
80 |
public void run() { |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
81 |
Point l = sb.getLocationOnScreen(); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
82 |
|
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
83 |
robot.mouseMove(l.x + (int) (0.75 * sb.getWidth()), l.y + sb.getHeight() / 2); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
84 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
85 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
86 |
} |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
87 |
}); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
88 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
89 |
toolkit.realSync(); |
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
90 |
|
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
91 |
SwingUtilities.invokeAndWait(new Runnable() { |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
92 |
public void run() { |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
93 |
Rectangle newThumbBounds = ui.getThumbBounds(); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
94 |
|
7786
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
95 |
if (!thumbBounds[0].equals(newThumbBounds)) { |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
96 |
throw new RuntimeException("Test failed.\nOld bounds: " + thumbBounds[0] + |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
97 |
"\nNew bounds: " + newThumbBounds); |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
98 |
} |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
99 |
} |
1db9d857af81
7007708: TEST: javax/swing/JScrollBar/6542335/bug6542335.java failes agaisnt jdk7 on solaris/linux
rupashka
parents:
6652
diff
changeset
|
100 |
}); |
6652
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
101 |
} |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
102 |
|
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
103 |
static class MyScrollBarUI extends BasicScrollBarUI { |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
104 |
public Rectangle getThumbBounds() { |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
105 |
return super.getThumbBounds(); |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
106 |
} |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
107 |
} |
482a7a13ef22
6542335: different behavior on knob of scroll bar between 1.4.2 and 5.0
alexp
parents:
diff
changeset
|
108 |
} |