bug6923305.java revision 15235:fe58d505fffd
1/*
2 * Copyright (c) 2010, 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 6923305
28 * @summary SynthSliderUI paints the slider track when the slider's "paintTrack" property is set to false
29 * @author Pavel Porvatov
30 * @run main bug6923305
31 */
32
33import javax.swing.*;
34import javax.swing.plaf.synth.SynthContext;
35import javax.swing.plaf.synth.SynthLookAndFeel;
36import javax.swing.plaf.synth.SynthSliderUI;
37import java.awt.*;
38import java.awt.image.BufferedImage;
39
40public class bug6923305 {
41    public static void main(String[] args) throws Exception {
42        UIManager.setLookAndFeel(new SynthLookAndFeel());
43
44        SwingUtilities.invokeAndWait(new Runnable() {
45            public void run() {
46                JSlider slider = new JSlider();
47
48                slider.setUI(new SynthSliderUI(slider) {
49                    @Override
50                    protected void paintTrack(SynthContext context, Graphics g, Rectangle trackBounds) {
51                        throw new RuntimeException("Test failed: the SynthSliderUI.paintTrack was invoked");
52                    }
53                });
54
55                slider.setPaintTrack(false);
56                slider.setSize(slider.getPreferredSize());
57
58                BufferedImage bufferedImage = new BufferedImage(slider.getWidth(), slider.getHeight(),
59                        BufferedImage.TYPE_INT_ARGB);
60
61                slider.paint(bufferedImage.getGraphics());
62            }
63        });
64    }
65}
66