Path: blob/master/test/jdk/javax/swing/JSlider/6524424/bug6524424.java
41153 views
/*1* Copyright (c) 2008, 2017, 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/* @test24* @bug 652442425* @requires (os.family == "windows")26* @summary JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings27* @author Pavel Porvatov28* @modules java.desktop/com.sun.java.swing.plaf.windows29* @run applet/manual=done bug6524424.html30*/3132import java.awt.*;33import javax.swing.*;3435import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;3637public class bug6524424 extends JApplet {38public static void main(String[] args) {39try {40UIManager.setLookAndFeel(new WindowsLookAndFeel());41} catch (UnsupportedLookAndFeelException e) {42e.printStackTrace();4344return;45}4647TestPanel panel = new TestPanel();4849JFrame frame = new JFrame();5051frame.setContentPane(panel);52frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);53frame.pack();54frame.setLocationRelativeTo(null);5556frame.setVisible(true);57}5859public void init() {60TestPanel panel = new TestPanel();6162setContentPane(panel);63}6465private static class TestPanel extends JPanel {6667private TestPanel() {68super(new GridBagLayout());6970JSlider slider1 = createSlider(1, 2);71JSlider slider2 = createSlider(2, 4);72JSlider slider3 = createSlider(3, 6);7374addComponent(this, slider1);75addComponent(this, slider2);76addComponent(this, slider3);77}7879private JSlider createSlider(int tickMinor, int tickMajor) {80JSlider result = new JSlider();8182result.setPaintLabels(true);83result.setPaintTicks(true);84result.setSnapToTicks(true);85result.setMinimum(0);86result.setMaximum(12);87result.setMinorTickSpacing(tickMinor);88result.setMajorTickSpacing(tickMajor);8990return result;91}92}9394private static void addComponent(JPanel panel, Component component) {95panel.add(component, new GridBagConstraints(0,96panel.getComponentCount(), 1, 1,971, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,98new Insets(0, 0, 0, 0), 0, 0));99}100}101102103