1 /*
   2  * Copyright (c) 2016, 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  /*
  25  @test
  26  @bug 8062946
  27  @summary Verify Transparency upon iconify/deiconify sequence
  28  @run main TransparencyTest
  29  */
  30 
  31 import java.awt.Robot;
  32 import javax.swing.JDialog;
  33 import javax.swing.JFrame;
  34 import javax.swing.SwingUtilities;
  35 
  36 public class TransparencyTest {
  37 
  38     private static JFrame frame;
  39     private static JDialog dialog;
  40     private static final int WIDTH = 250;
  41     private static final int HEIGHT = 250;
  42     private static final float OPACITY = 0.60f;
  43 
  44     public static void createAndShowGUI() {
  45         frame = new JFrame("JFrame");
  46         frame.setSize(WIDTH, HEIGHT);
  47 
  48         dialog = new JDialog(frame, false);
  49         dialog.setSize(250, 250);
  50         dialog.setUndecorated(true);
  51         dialog.setOpacity(OPACITY);
  52 
  53         frame.setLocationRelativeTo(null);
  54         dialog.setLocation(frame.getLocation().x + WIDTH + 10, frame.getLocation().y);
  55 
  56         frame.setVisible(true);
  57         dialog.setVisible(true);
  58     }
  59 
  60     public static void main(String[] args) throws Exception {
  61 
  62         Robot robot = new Robot();
  63         // create a GUI
  64         SwingUtilities.invokeAndWait(new Runnable() {
  65 
  66             @Override
  67             public void run() {
  68                 createAndShowGUI();
  69             }
  70         });
  71         robot.waitForIdle();
  72 
  73         // iconify frame
  74         SwingUtilities.invokeAndWait(new Runnable() {
  75 
  76             @Override
  77             public void run() {
  78                 frame.setExtendedState(JFrame.ICONIFIED);
  79             }
  80         });
  81         robot.waitForIdle();
  82 
  83         // deiconify frame
  84         SwingUtilities.invokeAndWait(new Runnable() {
  85 
  86             @Override
  87             public void run() {
  88                 frame.setExtendedState(JFrame.NORMAL);
  89             }
  90         });
  91         robot.waitForIdle();
  92 
  93         if (dialog.getOpacity() != OPACITY) {
  94             frame.dispose();
  95             throw new RuntimeException("JDialog transparency lost upon iconify/deiconify sequence");
  96         }
  97         frame.dispose();
  98     }
  99 }