Path: blob/master/test/jdk/javax/swing/JScrollBar/4865918/bug4865918.java
41153 views
/*1* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 486591827* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar28* @author Andrey Pikalev29* @run main bug486591830*/3132import javax.swing.*;33import java.awt.*;34import java.awt.event.*;35import java.util.*;3637public class bug4865918 {3839private static TestScrollBar sbar;40private static JFrame frame;4142public static void main(String[] argv) throws Exception {43try {44Robot robot = new Robot();45SwingUtilities.invokeAndWait(new Runnable() {4647public void run() {48createAndShowGUI();49}50});5152robot.waitForIdle();5354SwingUtilities.invokeAndWait(new Runnable() {5556@Override57public void run() {58sbar.pressMouse();59}60});6162robot.waitForIdle();6364int value = getValue();6566if (value != 9) {67throw new Error("The scrollbar block increment is incorect");68}69} finally {70if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());71}72}7374private static int getValue() throws Exception {75final int[] result = new int[1];7677SwingUtilities.invokeAndWait(new Runnable() {78@Override79public void run() {80result[0] = sbar.getValue();81}82});8384return result[0];85}8687private static void createAndShowGUI() {88frame = new JFrame("bug4865918");89frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);9091sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);92sbar.setPreferredSize(new Dimension(200, 20));93sbar.setBlockIncrement(10);9495frame.getContentPane().add(sbar);96frame.pack();97frame.setVisible(true);9899}100101static class TestScrollBar extends JScrollBar {102103public TestScrollBar(int orientation, int value, int extent,104int min, int max) {105super(orientation, value, extent, min, max);106107}108109public void pressMouse() {110MouseEvent me = new MouseEvent(sbar,111MouseEvent.MOUSE_PRESSED,112(new Date()).getTime(),113MouseEvent.BUTTON1_MASK,1143 * getWidth() / 4, getHeight() / 2,1151, true);116processMouseEvent(me);117}118}119}120121122