Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTabbedPane/8007563/Test8007563.java
38855 views
/*1* Copyright (c) 2014, 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* @bug 800756336* @summary Tests JTabbedPane background37* @author Sergey Malenkov38*/3940public class Test8007563 implements Runnable {41private static final ArrayList<String> LIST = new ArrayList<>();42private static final LookAndFeelInfo[] INFO = getInstalledLookAndFeels();43private static final CountDownLatch LATCH = new CountDownLatch(INFO.length);44private static Robot ROBOT;4546public static void main(String[] args) throws Exception {47ROBOT = new Robot();48invokeLater(new Test8007563());49LATCH.await();50if (!LIST.isEmpty()) {51throw new Error(LIST.toString());52}53}5455private static void addOpaqueError(boolean opaque) {56LIST.add(getLookAndFeel().getName() + " opaque=" + opaque);57}5859private static boolean updateLookAndFeel() {60int index = (int) LATCH.getCount() - 1;61if (index >= 0) {62try {63LookAndFeelInfo info = INFO[index];64System.err.println("L&F: " + info.getName());65setLookAndFeel(info.getClassName());66return true;67} catch (Exception exception) {68exception.printStackTrace();69}70}71return false;72}7374private JFrame frame;75private JTabbedPane pane;7677public void run() {78if (this.frame == null) {79if (!updateLookAndFeel()) {80return;81}82this.pane = new JTabbedPane();83this.pane.setOpaque(false);84this.pane.setBackground(Color.RED);85for (int i = 0; i < 3; i++) {86this.pane.addTab("Tab " + i, new JLabel("Content area " + i));87}88this.frame = new JFrame(getClass().getSimpleName());89this.frame.getContentPane().setBackground(Color.BLUE);90this.frame.add(this.pane);91this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);92this.frame.setSize(400, 200);93this.frame.setLocationRelativeTo(null);94this.frame.setVisible(true);95} else {96Point point = new Point(this.pane.getWidth() - 2, 2);97convertPointToScreen(point, this.pane);98Color actual = ROBOT.getPixelColor(point.x, point.y);99100boolean opaque = this.pane.isOpaque();101Color expected = opaque102? this.pane.getBackground()103: this.frame.getContentPane().getBackground();104105if (!expected.equals(actual)){106addOpaqueError(opaque);107}108if (!opaque) {109this.pane.setOpaque(true);110this.pane.repaint();111} else {112this.frame.dispose();113this.frame = null;114this.pane = null;115LATCH.countDown();116}117118}119SecondaryLoop secondaryLoop =120Toolkit.getDefaultToolkit().getSystemEventQueue()121.createSecondaryLoop();122new Thread() {123@Override124public void run() {125try {126Thread.sleep(200);127} catch (InterruptedException e) {128}129secondaryLoop.exit();130invokeLater(Test8007563.this);131}132}.start();133secondaryLoop.enter();134}135}136137138