jdk/test/javax/swing/plaf/nimbus/8041642/ScrollBarThumbVisibleTest.java
author goetz
Fri, 28 Jul 2017 14:06:28 +0200
changeset 46151 5fa789776f7d
parent 33856 875f59862274
permissions -rw-r--r--
8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests. Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows. Reviewed-by: serb, mbaesken
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
/*
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33856
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
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    24
/**
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    25
 * @test
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    26
 * @key headful
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    27
 * @bug 8134828
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    28
 * @summary Scrollbar thumb disappears with Nimbus L&F
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    29
 * @author Semyon Sadetsky
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    30
 */
33856
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    31
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    32
import javax.swing.*;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    33
import java.awt.*;
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
public class ScrollBarThumbVisibleTest
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    36
{
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    37
    private static JFrame frame;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    38
    private static Point point;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    39
    private static JScrollBar bar;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    40
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    42
        for (UIManager.LookAndFeelInfo info : UIManager
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    43
                .getInstalledLookAndFeels()) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    44
            if ("Nimbus".equals(info.getName())) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    45
                try {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    46
                    UIManager.setLookAndFeel(info.getClassName());
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    47
                } catch (Exception ex) {
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
                break;
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    50
            }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    51
        }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    52
        try {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    53
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    54
                public void run() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    55
                    frame = new JFrame();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    56
                    frame.setUndecorated(true);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    57
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    58
                    setup(frame);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    59
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    60
            });
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    61
            final Robot robot = new Robot();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    62
            robot.delay(200);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    63
            robot.waitForIdle();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    64
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    65
                @Override
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    66
                public void run() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    67
                    point = bar.getLocationOnScreen();
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    68
                }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    69
            });
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    70
            Color color1 = robot.getPixelColor(point.x + 48, point.y + 55);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    71
            Color color2 = robot.getPixelColor(point.x + 48, point.y + 125);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    72
            System.out.println(color1);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    73
            System.out.println(color2);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    74
           if (color1.equals(color2)) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    75
                throw new RuntimeException("Thump is not visible");
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    76
            }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    77
        } finally {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    78
            SwingUtilities.invokeAndWait(new Runnable() {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    79
                @Override
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    80
                public void run() {
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 33856
diff changeset
    81
                    if (frame != null) { frame.dispose(); }
33856
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
            });
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
        System.out.println("ok");
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    86
    }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    87
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    88
    static void setup(JFrame frame) {
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    89
        bar = new JScrollBar(Adjustable.VERTICAL, 500, 0, 0, 1000);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    90
        frame.getContentPane().add(bar);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    91
        frame.setSize(50, 250);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    92
        frame.setLocation(100, 100);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    93
        frame.setVisible(true);
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    94
    }
875f59862274 8134828: Scrollbar thumb disappears with Nimbus L&F
ssadetsky
parents:
diff changeset
    95
}