jdk/test/javax/swing/plaf/nimbus/8041642/ScrollBarThumbVisibleTest.java
author ssadetsky
Thu, 29 Oct 2015 18:43:21 +0300
changeset 33856 875f59862274
child 46151 5fa789776f7d
permissions -rw-r--r--
8134828: Scrollbar thumb disappears with Nimbus L&F Reviewed-by: alexsch, alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33856
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     1
/*
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     4
 *
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     7
 * published by the Free Software Foundation.
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     8
 *
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    13
 * accompanied this code).
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    14
 *
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    18
 *
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    21
 * questions.
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    22
 */
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    23
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    24
/* @test
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    25
   @bug 8134828
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    26
   @summary Scrollbar thumb disappears with Nimbus L&F
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    27
   @author Semyon Sadetsky
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    28
*/
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    29
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    30
import javax.swing.*;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    31
import java.awt.*;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    32
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    33
public class ScrollBarThumbVisibleTest
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    34
{
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    35
    private static JFrame frame;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    36
    private static Point point;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    37
    private static JScrollBar bar;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    38
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    40
        for (UIManager.LookAndFeelInfo info : UIManager
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    41
                .getInstalledLookAndFeels()) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    42
            if ("Nimbus".equals(info.getName())) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    43
                try {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    44
                    UIManager.setLookAndFeel(info.getClassName());
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    45
                } catch (Exception ex) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    46
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    47
                break;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    48
            }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    49
        }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    50
        try {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    51
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    52
                public void run() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    53
                    frame = new JFrame();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    54
                    frame.setUndecorated(true);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    55
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    56
                    setup(frame);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    57
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    58
            });
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    59
            final Robot robot = new Robot();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    60
            robot.delay(200);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    61
            robot.waitForIdle();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    62
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    63
                @Override
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    64
                public void run() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    65
                    point = bar.getLocationOnScreen();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    66
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    67
            });
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    68
            Color color1 = robot.getPixelColor(point.x + 48, point.y + 55);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    69
            Color color2 = robot.getPixelColor(point.x + 48, point.y + 125);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    70
            System.out.println(color1);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    71
            System.out.println(color2);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    72
           if (color1.equals(color2)) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    73
                throw new RuntimeException("Thump is not visible");
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    74
            }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    75
        } finally {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    76
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    77
                @Override
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    78
                public void run() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    79
                    frame.dispose();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    80
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    81
            });
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    82
        }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    83
        System.out.println("ok");
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    84
    }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    85
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    86
    static void setup(JFrame frame) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    87
        bar = new JScrollBar(Adjustable.VERTICAL, 500, 0, 0, 1000);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    88
        frame.getContentPane().add(bar);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    89
        frame.setSize(50, 250);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    90
        frame.setLocation(100, 100);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    91
        frame.setVisible(true);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    92
    }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    93
}