1 /* 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @key headful 27 * @bug 4865918 28 * @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar 29 * @author Andrey Pikalev 30 * @run main bug4865918 31 */ 32 33 import javax.swing.*; 34 import java.awt.*; 35 import java.awt.event.*; 36 import java.util.*; 37 import sun.awt.SunToolkit; 38 39 public class bug4865918 { 40 41 private static TestScrollBar sbar; 42 43 public static void main(String[] argv) throws Exception { 44 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 45 46 SwingUtilities.invokeAndWait(new Runnable() { 47 48 public void run() { 49 createAndShowGUI(); 50 } 51 }); 52 53 toolkit.realSync(); 54 55 SwingUtilities.invokeAndWait(new Runnable() { 56 57 @Override 58 public void run() { 59 sbar.pressMouse(); 60 } 61 }); 62 63 toolkit.realSync(); 64 65 int value = getValue(); 66 67 if (value != 9) { 68 throw new Error("The scrollbar block increment is incorect"); 69 } 70 } 71 72 private static int getValue() throws Exception { 73 final int[] result = new int[1]; 74 75 SwingUtilities.invokeAndWait(new Runnable() { 76 @Override 77 public void run() { 78 result[0] = sbar.getValue(); 79 } 80 }); 81 82 return result[0]; 83 } 84 85 private static void createAndShowGUI() { 86 JFrame frame = new JFrame("bug4865918"); 87 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 88 89 sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100); 90 sbar.setPreferredSize(new Dimension(200, 20)); 91 sbar.setBlockIncrement(10); 92 93 frame.getContentPane().add(sbar); 94 frame.pack(); 95 frame.setVisible(true); 96 97 } 98 99 static class TestScrollBar extends JScrollBar { 100 101 public TestScrollBar(int orientation, int value, int extent, 102 int min, int max) { 103 super(orientation, value, extent, min, max); 104 105 } 106 107 public void pressMouse() { 108 MouseEvent me = new MouseEvent(sbar, 109 MouseEvent.MOUSE_PRESSED, 110 (new Date()).getTime(), 111 MouseEvent.BUTTON1_MASK, 112 3 * getWidth() / 4, getHeight() / 2, 113 1, true); 114 processMouseEvent(me); 115 } 116 } 117 }