Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java
38918 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* @bug 486591826* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar27* @author Andrey Pikalev28* @run main bug486591829*/3031import javax.swing.*;32import java.awt.*;33import java.awt.event.*;34import java.util.*;3536public class bug4865918 {3738private static TestScrollBar sbar;3940public static void main(String[] argv) throws Exception {4142Robot robot = new Robot();43SwingUtilities.invokeAndWait(new Runnable() {4445public void run() {46createAndShowGUI();47}48});4950robot.waitForIdle();5152SwingUtilities.invokeAndWait(new Runnable() {5354@Override55public void run() {56sbar.pressMouse();57}58});5960robot.waitForIdle();6162int value = getValue();6364if (value != 9) {65throw new Error("The scrollbar block increment is incorect");66}67}6869private static int getValue() throws Exception {70final int[] result = new int[1];7172SwingUtilities.invokeAndWait(new Runnable() {73@Override74public void run() {75result[0] = sbar.getValue();76}77});7879return result[0];80}8182private static void createAndShowGUI() {83JFrame frame = new JFrame("bug4865918");84frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);8586sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);87sbar.setPreferredSize(new Dimension(200, 20));88sbar.setBlockIncrement(10);8990frame.getContentPane().add(sbar);91frame.pack();92frame.setVisible(true);9394}9596static class TestScrollBar extends JScrollBar {9798public TestScrollBar(int orientation, int value, int extent,99int min, int max) {100super(orientation, value, extent, min, max);101102}103104public void pressMouse() {105MouseEvent me = new MouseEvent(sbar,106MouseEvent.MOUSE_PRESSED,107(new Date()).getTime(),108MouseEvent.BUTTON1_MASK,1093 * getWidth() / 4, getHeight() / 2,1101, true);111processMouseEvent(me);112}113}114}115116117