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