2783N/A/*
3909N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
2783N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2783N/A *
2783N/A * This code is free software; you can redistribute it and/or modify it
2783N/A * under the terms of the GNU General Public License version 2 only, as
2783N/A * published by the Free Software Foundation.
2783N/A *
2783N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2783N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2783N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2783N/A * version 2 for more details (a copy is included in the LICENSE file that
2783N/A * accompanied this code).
2783N/A *
2783N/A * You should have received a copy of the GNU General Public License version
2783N/A * 2 along with this work; if not, write to the Free Software Foundation,
2783N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2783N/A *
2783N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2783N/A * or visit www.oracle.com if you need additional information or have any
2783N/A * questions.
2783N/A */
2783N/A
2783N/A/* @test
2783N/A @bug 6542335
2783N/A @summary different behavior on knob of scroll bar between 1.4.2 and 5.0
2783N/A @author Alexander Potochkin
2783N/A @run main bug6542335
2783N/A*/
2783N/A
2783N/Aimport sun.awt.SunToolkit;
2783N/A
2783N/Aimport javax.swing.*;
2783N/Aimport javax.swing.plaf.basic.BasicScrollBarUI;
2783N/Aimport java.awt.*;
2783N/Aimport java.awt.event.InputEvent;
2783N/A
2783N/Apublic class bug6542335 {
2783N/A private static JScrollBar sb;
2783N/A private static MyScrollBarUI ui;
2783N/A
2783N/A public static void main(String[] args) throws Exception {
3306N/A final Robot robot = new Robot();
2783N/A robot.setAutoDelay(10);
2783N/A
2783N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
2783N/A
3306N/A final Rectangle[] thumbBounds = new Rectangle[1];
3306N/A
2783N/A SwingUtilities.invokeAndWait(new Runnable() {
2783N/A public void run() {
2783N/A final JFrame frame = new JFrame("bug6542335");
2783N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2783N/A
2783N/A sb = new JScrollBar(0, 0, 1, 0, 1);
2783N/A
2783N/A ui = new MyScrollBarUI();
2783N/A sb.setUI(ui);
2783N/A
2783N/A sb.setPreferredSize(new Dimension(200, 17));
2783N/A DefaultBoundedRangeModel rangeModel = new DefaultBoundedRangeModel();
2783N/A rangeModel.setMaximum(100);
2783N/A rangeModel.setMinimum(0);
2783N/A rangeModel.setExtent(50);
2783N/A rangeModel.setValue(50);
2783N/A
2783N/A sb.setModel(rangeModel);
3306N/A frame.add(sb, BorderLayout.NORTH);
2783N/A
2783N/A frame.setSize(200, 100);
2783N/A frame.setVisible(true);
2783N/A }
2783N/A });
2783N/A
3306N/A toolkit.realSync();
3306N/A
3306N/A SwingUtilities.invokeAndWait(new Runnable() {
3306N/A public void run() {
3560N/A thumbBounds[0] = new Rectangle(ui.getThumbBounds());
3560N/A
3306N/A Point l = sb.getLocationOnScreen();
3306N/A
3306N/A robot.mouseMove(l.x + (int) (0.75 * sb.getWidth()), l.y + sb.getHeight() / 2);
3306N/A robot.mousePress(InputEvent.BUTTON1_MASK);
3306N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
3306N/A }
3306N/A });
2783N/A
2783N/A toolkit.realSync();
3306N/A
3306N/A SwingUtilities.invokeAndWait(new Runnable() {
3306N/A public void run() {
3306N/A Rectangle newThumbBounds = ui.getThumbBounds();
2783N/A
3306N/A if (!thumbBounds[0].equals(newThumbBounds)) {
3306N/A throw new RuntimeException("Test failed.\nOld bounds: " + thumbBounds[0] +
3306N/A "\nNew bounds: " + newThumbBounds);
3306N/A }
3306N/A }
3306N/A });
2783N/A }
2783N/A
2783N/A static class MyScrollBarUI extends BasicScrollBarUI {
2783N/A public Rectangle getThumbBounds() {
2783N/A return super.getThumbBounds();
2783N/A }
2783N/A }
2783N/A}