1 /* 2 * Copyright (c) 2011, 2014, 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 /* @test 24 @bug 6401380 25 @summary JSlider - mouse click ont the left side of the knob is ignored. 26 @library ../../../../lib/testlibrary 27 @build ExtendedRobot 28 @author Alexander Potochkin 29 @run main bug6401380 30 */ 31 32 import javax.swing.*; 33 import javax.swing.plaf.basic.BasicSliderUI; 34 import java.awt.*; 35 import java.awt.event.InputEvent; 36 37 public class bug6401380 extends JFrame { 38 private static JSlider slider; 39 40 public bug6401380() { 41 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 42 43 slider = new JSlider(); 44 slider.setMajorTickSpacing(0); 45 slider.setMaximum(50); 46 slider.setMinorTickSpacing(10); 47 slider.setPaintLabels(true); 48 slider.setPaintTicks(true); 49 slider.setSnapToTicks(true); 50 51 // MetalSliderUI overrides scrollDueToClickInTrack() method 52 // so this test doens't work for Metal 53 slider.setUI(new BasicSliderUI(slider)); 54 55 add(slider); 56 setSize(200, 200); 57 } 58 59 public static void main(String[] args) throws Exception { 60 61 ExtendedRobot robot = new ExtendedRobot(); 62 robot.setAutoDelay(10); 63 64 SwingUtilities.invokeAndWait(new Runnable() { 65 public void run() { 66 new bug6401380().setVisible(true); 67 } 68 }); 69 robot.waitForIdle(); 70 71 Point l = slider.getLocationOnScreen(); 72 robot.glide(0, 0, l.x + slider.getWidth() / 2, l.y + slider.getHeight() / 2); 73 robot.mousePress(InputEvent.BUTTON1_MASK); 74 robot.mouseRelease(InputEvent.BUTTON1_MASK); 75 76 robot.waitForIdle(); 77 78 if (slider.getValue() == slider.getMaximum()) { 79 throw new RuntimeException("Slider value unchanged"); 80 } 81 } 82 }