Path: blob/master/test/jdk/javax/swing/JTabbedPane/8007563/Test8007563.java
41155 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.*;24import java.util.ArrayList;25import java.util.concurrent.CountDownLatch;26import javax.swing.JFrame;27import javax.swing.JLabel;28import javax.swing.JTabbedPane;2930import static javax.swing.UIManager.*;31import static javax.swing.SwingUtilities.*;3233/*34* @test35* @key headful36* @bug 800756337* @summary Tests JTabbedPane background38* @author Sergey Malenkov39*/4041public class Test8007563 implements Runnable {42private static final ArrayList<String> LIST = new ArrayList<>();43private static final LookAndFeelInfo[] INFO = getInstalledLookAndFeels();44private static final CountDownLatch LATCH = new CountDownLatch(INFO.length);45private static Robot ROBOT;4647public static void main(String[] args) throws Exception {48ROBOT = new Robot();49invokeLater(new Test8007563());50LATCH.await();51if (!LIST.isEmpty()) {52throw new Error(LIST.toString());53}54}5556private static void addOpaqueError(boolean opaque) {57LIST.add(getLookAndFeel().getName() + " opaque=" + opaque);58}5960private static boolean updateLookAndFeel() {61int index = (int) LATCH.getCount() - 1;62if (index >= 0) {63try {64LookAndFeelInfo info = INFO[index];65System.err.println("L&F: " + info.getName());66setLookAndFeel(info.getClassName());67return true;68} catch (Exception exception) {69exception.printStackTrace();70}71}72return false;73}7475private JFrame frame;76private JTabbedPane pane;7778public void run() {79if (this.frame == null) {80if (!updateLookAndFeel()) {81return;82}83this.pane = new JTabbedPane();84this.pane.setOpaque(false);85this.pane.setBackground(Color.RED);86for (int i = 0; i < 3; i++) {87this.pane.addTab("Tab " + i, new JLabel("Content area " + i));88}89this.frame = new JFrame(getClass().getSimpleName());90this.frame.getContentPane().setBackground(Color.BLUE);91this.frame.add(this.pane);92this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);93this.frame.setSize(400, 200);94this.frame.setLocationRelativeTo(null);95this.frame.setVisible(true);96} else {97Point point = new Point(this.pane.getWidth() - 2, 2);98convertPointToScreen(point, this.pane);99Color actual = ROBOT.getPixelColor(point.x, point.y);100101boolean opaque = this.pane.isOpaque();102Color expected = opaque103? this.pane.getBackground()104: this.frame.getContentPane().getBackground();105106if (!expected.equals(actual)){107addOpaqueError(opaque);108}109if (!opaque) {110this.pane.setOpaque(true);111this.pane.repaint();112} else {113this.frame.dispose();114this.frame = null;115this.pane = null;116LATCH.countDown();117}118119}120SecondaryLoop secondaryLoop =121Toolkit.getDefaultToolkit().getSystemEventQueue()122.createSecondaryLoop();123new Thread() {124@Override125public void run() {126try {127Thread.sleep(200);128} catch (InterruptedException e) {129}130secondaryLoop.exit();131invokeLater(Test8007563.this);132}133}.start();134secondaryLoop.enter();135}136}137138139