jdk/test/javax/swing/LookAndFeel/6439354/TitledBorderTest.java
author pkbalakr
Thu, 24 Mar 2016 16:56:13 +0530
changeset 36908 0af5f1faaeed
child 37703 1351ca507713
permissions -rw-r--r--
6439354: Win L&F: TitledBorder colors are not from desktop Reviewed-by: ssadetsky, rchamyal, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36908
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     1
/*
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     4
 *
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     8
 *
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    13
 * accompanied this code).
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    14
 *
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    18
 *
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    21
 * questions.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    22
 */
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    23
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    24
 /*
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    25
 * @test
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    26
 * @bug 6439354
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    27
 * @summary Verify TitleBorder appearance Color/Visibility for WLAF
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    28
 * @requires (os.family == "windows")
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    29
 * @run main/manual TitledBorderTest
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    30
 */
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    31
import java.awt.Color;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    32
import java.awt.GridBagConstraints;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    33
import java.awt.GridBagLayout;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    34
import java.awt.event.ActionEvent;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    35
import java.awt.event.ActionListener;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    36
import javax.swing.BorderFactory;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    37
import javax.swing.JButton;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    38
import javax.swing.JFrame;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    39
import javax.swing.JPanel;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    40
import javax.swing.JTextArea;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    41
import javax.swing.SwingUtilities;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    42
import javax.swing.UIManager;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    43
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    44
public class TitledBorderTest implements ActionListener {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    45
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    46
    private static GridBagLayout layout;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    47
    private static JPanel mainControlPanel;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    48
    private static JPanel resultButtonPanel;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    49
    private static JTextArea instructionTextArea;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    50
    private static JButton passButton;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    51
    private static JButton failButton;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    52
    private static JFrame mainFrame;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    53
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    54
    public static void main(String[] args) throws Exception {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    55
        TitledBorderTest titledBorderTest = new TitledBorderTest();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    56
    }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    57
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    58
    public TitledBorderTest() throws Exception {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    59
        createUI();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    60
    }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    61
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    62
    public final void createUI() throws Exception {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    63
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    64
        UIManager.setLookAndFeel("com.sun.java.swing.plaf."
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    65
                + "windows.WindowsLookAndFeel");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    66
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    67
        SwingUtilities.invokeAndWait(() -> {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    68
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    69
            mainFrame = new JFrame("Window LAF TitledBorder Test");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    70
            layout = new GridBagLayout();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    71
            mainControlPanel = new JPanel(layout);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    72
            resultButtonPanel = new JPanel(layout);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    73
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    74
            GridBagConstraints gbc = new GridBagConstraints();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    75
            String instructions
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    76
                    = "INSTRUCTIONS:"
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    77
                    + "\n set Windows Theme to HighContrast#1."
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    78
                    + "\n (ControlPanel->Personalization->High Contrast#1)"
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    79
                    + "\n If Titled Border(Border Line) is visible then test"
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    80
                    + " passes else failed.";
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    81
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    82
            instructionTextArea = new JTextArea();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    83
            instructionTextArea.setText(instructions);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    84
            instructionTextArea.setEnabled(false);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    85
            instructionTextArea.setDisabledTextColor(Color.black);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    86
            instructionTextArea.setBackground(Color.white);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    87
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    88
            gbc.gridx = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    89
            gbc.gridy = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    90
            gbc.fill = GridBagConstraints.HORIZONTAL;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    91
            mainControlPanel.add(instructionTextArea, gbc);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    92
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    93
            mainControlPanel.setBorder(BorderFactory.
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    94
                    createTitledBorder("Titled Border"));
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    95
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    96
            passButton = new JButton("Pass");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    97
            passButton.setActionCommand("Pass");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    98
            passButton.addActionListener(TitledBorderTest.this);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
    99
            failButton = new JButton("Fail");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   100
            failButton.setActionCommand("Fail");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   101
            failButton.addActionListener(TitledBorderTest.this);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   102
            gbc.gridx = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   103
            gbc.gridy = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   104
            resultButtonPanel.add(passButton, gbc);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   105
            gbc.gridx = 1;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   106
            gbc.gridy = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   107
            resultButtonPanel.add(failButton, gbc);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   108
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   109
            gbc.gridx = 0;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   110
            gbc.gridy = 1;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   111
            mainControlPanel.add(resultButtonPanel, gbc);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   112
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   113
            mainFrame.add(mainControlPanel);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   114
            mainFrame.pack();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   115
            mainFrame.setVisible(true);
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   116
        });
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   117
    }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   118
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   119
    @Override
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   120
    public void actionPerformed(ActionEvent evt) {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   121
        if (evt.getSource() instanceof JButton) {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   122
            JButton btn = (JButton) evt.getSource();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   123
            cleanUp();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   124
            switch (btn.getActionCommand()) {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   125
                case "Pass":
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   126
                    break;
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   127
                case "Fail":
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   128
                    throw new AssertionError("User Clicked Fail!");
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   129
            }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   130
        }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   131
    }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   132
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   133
    private static void cleanUp() {
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   134
        mainFrame.dispose();
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   135
    }
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   136
0af5f1faaeed 6439354: Win L&F: TitledBorder colors are not from desktop
pkbalakr
parents:
diff changeset
   137
}