1 /*
   2  * Copyright (c) 2013, 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 import java.awt.Dialog;
  24 import java.awt.Frame;
  25 import java.awt.Toolkit;
  26 import java.awt.Window;
  27 import sun.awt.SunToolkit;
  28 /**
  29  * @test
  30  * @bug 7081594
  31  * @author Alexander Scherbatiy
  32  * @summary Windows owned by an always-on-top window DO NOT automatically become always-on-top
  33  * @run main AlwaysOnTopFieldTest
  34  */
  35 public class AlwaysOnTopFieldTest {
  36 
  37     public static void main(String[] args) {
  38         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  39 
  40         Window window = new Frame("Window 1");
  41         window.setSize(200, 200);
  42         window.setAlwaysOnTop(true);
  43         window.setVisible(true);
  44         toolkit.realSync();
  45 
  46         Dialog dialog = new Dialog(window, "Owned dialog 1");
  47         dialog.setSize(200, 200);
  48         dialog.setLocation(100, 100);
  49         dialog.setVisible(true);
  50         toolkit.realSync();
  51 
  52         try {
  53             if (!window.isAlwaysOnTop()) {
  54                 throw new RuntimeException("Window has wrong isAlwaysOnTop value");
  55             }
  56             if (!dialog.isAlwaysOnTop()) {
  57                 throw new RuntimeException("Dialog has wrong isAlwaysOnTop value");
  58             }
  59         } finally {
  60             window.dispose();
  61             dialog.dispose();
  62         }
  63 
  64         window = new Frame("Window 2");
  65         window.setSize(200, 200);
  66         window.setVisible(true);
  67         toolkit.realSync();
  68 
  69 
  70         dialog = new Dialog(window, "Owned dialog 2");
  71         dialog.setSize(200, 200);
  72         dialog.setLocation(100, 100);
  73         dialog.setVisible(true);
  74         toolkit.realSync();
  75 
  76         window.setAlwaysOnTop(true);
  77         toolkit.realSync();
  78 
  79         try {
  80             if (!window.isAlwaysOnTop()) {
  81                 throw new RuntimeException("Window has wrong isAlwaysOnTop value");
  82             }
  83             if (!dialog.isAlwaysOnTop()) {
  84                 throw new RuntimeException("Dialog has wrong isAlwaysOnTop value");
  85             }
  86         } finally {
  87             window.dispose();
  88             dialog.dispose();
  89         }
  90     }
  91 }