0N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 6848475
0N/A * @summary JSlider does not display the correct value of its BoundedRangeModel
0N/A * @author Pavel Porvatov
0N/A * @run main bug6848475
0N/A */
0N/A
0N/Aimport sun.awt.SunToolkit;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.plaf.SliderUI;
0N/Aimport javax.swing.plaf.basic.BasicSliderUI;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.InputEvent;
0N/Aimport java.lang.reflect.Field;
0N/A
0N/Apublic class bug6848475 {
0N/A private static JFrame frame;
0N/A
0N/A private static JSlider slider;
0N/A
0N/A private static Robot robot;
0N/A
0N/A private static int thumbRectX;
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
0N/A
0N/A robot = new Robot();
0N/A robot.setAutoDelay(100);
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A frame = new JFrame();
0N/A
0N/A DefaultBoundedRangeModel sliderModel = new DefaultBoundedRangeModel() {
0N/A public void setValue(int n) {
0N/A // Don't allow value to be changed
0N/A }
0N/A };
0N/A
0N/A slider = new JSlider(sliderModel);
0N/A
0N/A frame.getContentPane().add(slider);
0N/A frame.pack();
0N/A frame.setVisible(true);
0N/A }
0N/A });
0N/A
0N/A toolkit.realSync();
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A Point p = slider.getLocationOnScreen();
0N/A
0N/A robot.mouseMove(p.x, p.y);
0N/A }
0N/A });
0N/A
0N/A toolkit.realSync();
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A thumbRectX = getThumbRectField().x;
0N/A
0N/A Point p = slider.getLocationOnScreen();
0N/A
0N/A robot.mouseMove(p.x, p.y);
0N/A robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
0N/A robot.mouseMove(p.x + 20, p.y);
0N/A robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
0N/A }
0N/A });
0N/A
0N/A toolkit.realSync();
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
Rectangle newThumbRect = getThumbRectField();
if (newThumbRect.x != thumbRectX) {
throw new RuntimeException("Test failed: the thumb was moved");
}
frame.dispose();
}
});
}
private static Rectangle getThumbRectField() {
try {
SliderUI ui = slider.getUI();
Field field = BasicSliderUI.class.getDeclaredField("thumbRect");
field.setAccessible(true);
return (Rectangle) field.get(ui);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}