jdk/test/javax/swing/JSlider/6587742/bug6587742.java
author rupashka
Wed, 10 Sep 2008 19:16:14 +0400
changeset 1317 0ba1e3d36c19
child 5506 202f599c92aa
permissions -rw-r--r--
6587742: filling half of a JSlider's track is no longer optional Summary: now OceanTheme uses the JSlider.isFilled property like other themes Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     1
/*
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     4
 *
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     8
 *
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    13
 * accompanied this code).
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    14
 *
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    18
 *
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    21
 * have any questions.
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    22
 */
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    23
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    24
/* @test
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    25
 * @bug 6587742
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    26
 * @summary filling half of a JSlider's track is no longer optional
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    27
 * @author Pavel Porvatov
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    28
 * @run applet/manual=done bug6587742.html
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    29
 */
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    30
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    31
import javax.swing.*;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    32
import javax.swing.plaf.metal.DefaultMetalTheme;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    33
import javax.swing.plaf.metal.MetalLookAndFeel;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    34
import javax.swing.plaf.metal.MetalTheme;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    35
import javax.swing.plaf.metal.OceanTheme;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    36
import java.awt.event.ItemEvent;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    37
import java.awt.event.ItemListener;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    38
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    39
public class bug6587742 extends JApplet {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    40
    public void init() {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    41
        TestPanel panel = new TestPanel();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    42
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    43
        setContentPane(panel);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    44
    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    45
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    46
    private class TestPanel extends JPanel {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    47
        private final JComboBox cbThemes = new JComboBox();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    48
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    49
        private TestPanel() {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    50
            // Fill cbThemes
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    51
            cbThemes.addItem(new OceanTheme());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    52
            cbThemes.addItem(new DefaultMetalTheme());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    53
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    54
            cbThemes.addItemListener(new ItemListener() {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    55
                public void itemStateChanged(ItemEvent e) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    56
                    MetalTheme theme = (MetalTheme) cbThemes.getSelectedItem();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    57
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    58
                    if (theme != null) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    59
                        MetalLookAndFeel.setCurrentTheme(theme);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    60
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    61
                        // re-install the Metal Look and Feel
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    62
                        try {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    63
                            UIManager.setLookAndFeel(new MetalLookAndFeel());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    64
                        } catch (UnsupportedLookAndFeelException e1) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    65
                            JOptionPane.showMessageDialog(TestPanel.this, "Can't change theme: " + e1.getMessage(),
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    66
                                    "Error", JOptionPane.ERROR_MESSAGE);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    67
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    68
                            return;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    69
                        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    70
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    71
                        SwingUtilities.updateComponentTreeUI(bug6587742.this);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    72
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    73
                }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    74
            });
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    75
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    76
            JPanel pnVertical = new JPanel();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    77
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    78
            pnVertical.setLayout(new BoxLayout(pnVertical, BoxLayout.Y_AXIS));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    79
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    80
            for (int i = 0; i < 12; i++) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    81
                int filled = i >> 2;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    82
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    83
                pnVertical.add(createSlider(false, filled > 1 ? null : Boolean.valueOf(filled == 1), (i & 2) == 0,
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    84
                        (i & 1) != 0));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    85
            }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    86
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    87
            JPanel pnHorizontal = new JPanel();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    88
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    89
            pnHorizontal.setLayout(new BoxLayout(pnHorizontal, BoxLayout.X_AXIS));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    90
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    91
            for (int i = 0; i < 12; i++) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    92
                int filled = i >> 2;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    93
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    94
                pnHorizontal.add(createSlider(true, filled > 1 ? null : Boolean.valueOf(filled == 1), (i & 2) == 0,
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    95
                        (i & 1) != 0));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    96
            }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    97
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    98
            JTabbedPane tpSliders = new JTabbedPane();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
    99
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   100
            tpSliders.add("Vertical sliders", pnVertical);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   101
            tpSliders.add("Horizontal sliders", pnHorizontal);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   102
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   103
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   104
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   105
            add(new JLabel("Select theme:"));
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   106
            add(cbThemes);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   107
            add(tpSliders);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   108
        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   109
    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   110
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   111
    private static JSlider createSlider(boolean vertical, Boolean filled, boolean enabled, boolean inverted) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   112
        JSlider result = new JSlider(vertical ? SwingConstants.VERTICAL : SwingConstants.HORIZONTAL, 0, 100, 50);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   113
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   114
        result.setMajorTickSpacing(20);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   115
        result.setMinorTickSpacing(5);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   116
        result.setPaintTicks(true);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   117
        result.setPaintLabels(true);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   118
        result.setEnabled(enabled);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   119
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   120
        if (filled != null) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   121
            result.putClientProperty("JSlider.isFilled", filled);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   122
        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   123
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   124
        result.setInverted(inverted);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   125
        result.setToolTipText("<html>vertical = " + vertical + "<br>enabled = " + enabled + "<br>filled = " + filled +
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   126
                "<br>inverted = " + inverted + "</html>");
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   127
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   128
        return result;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   129
    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
diff changeset
   130
}