bug6278700.java revision 2362
633N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
633N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
633N/A *
633N/A * This code is free software; you can redistribute it and/or modify it
633N/A * under the terms of the GNU General Public License version 2 only, as
633N/A * published by the Free Software Foundation.
633N/A *
633N/A * This code is distributed in the hope that it will be useful, but WITHOUT
633N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
633N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
633N/A * version 2 for more details (a copy is included in the LICENSE file that
633N/A * accompanied this code).
633N/A *
633N/A * You should have received a copy of the GNU General Public License version
633N/A * 2 along with this work; if not, write to the Free Software Foundation,
633N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
633N/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.
633N/A */
633N/A
633N/A/* @test
633N/A * @bug 6278700
633N/A * @summary JSlider created with BoundedRangeModel fires twice when changed
633N/A * @author Pavel Porvatov
633N/A @run main bug6278700
633N/A */
633N/A
633N/Aimport javax.swing.*;
633N/Aimport javax.swing.event.ChangeEvent;
633N/Aimport javax.swing.event.ChangeListener;
633N/A
633N/Apublic class bug6278700 {
633N/A private int changeCount;
633N/A
633N/A private final ChangeListener listener = new ChangeListener() {
633N/A public void stateChanged(ChangeEvent e) {
633N/A changeCount++;
633N/A }
633N/A };
633N/A
633N/A public static void main(String[] args) {
633N/A new bug6278700();
633N/A }
633N/A
633N/A public bug6278700() {
633N/A SwingUtilities.invokeLater(new Runnable() {
633N/A public void run() {
633N/A JSlider slider = new JSlider(new DefaultBoundedRangeModel(5, 0, 0, 10));
633N/A
633N/A slider.addChangeListener(listener);
633N/A slider.setValue(0);
633N/A
633N/A if (changeCount != 1) {
633N/A throw new RuntimeException("Incorrect stateChanged count: " + Integer.toString(changeCount));
633N/A }
633N/A
633N/A changeCount = 0;
633N/A
633N/A slider = new JSlider();
633N/A
633N/A slider.addChangeListener(listener);
633N/A slider.setValue(0);
633N/A
633N/A if (changeCount != 1) {
633N/A throw new RuntimeException("Incorrect stateChanged count: " + Integer.toString(changeCount));
633N/A }
633N/A }
633N/A });
633N/A }
633N/A}