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