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