Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7081602

Window.setAlwaysOnTop(false: the window doesn't remain in the top-most position in solaris

XMLWordPrintable

    • x86
    • solaris_10

        From the java.awt.Window.setAlwaysOnTop(boolean) spec:

        "When this method is called on a window with a value of false the always-on-top state is set to normal. The window remains in the top-most position but it`s z-order can be changed as for any other window. Calling this method with a value of false on a window that has a normal state has no effect. Setting the always-on-top state to false has no effect on the relative z-order of the windows if there are no other always-on-top windows."


        Mini-Test:

        /*
         * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
         */

        import java.awt.*;
        import java.util.concurrent.CountDownLatch;

        /**
         * @author Alexey Fyodorov
         */
        public class NormalStateRestoredTest {

            private static final int SIZE = 200;

            private Robot robot;

            public NormalStateRestoredTest() {
                try {
                    robot = new Robot();
                    robot.setAutoDelay(200);
                    robot.setAutoWaitForIdle(true);
                } catch (AWTException e) {
                    e.printStackTrace();
                }
            }

            public static void main(String[] args) {
                new NormalStateRestoredTest().test();
            }

            private void test() {
                Window alwaysOnTopWindow = null;
                Window anotherWindow = null;
                try {
                    alwaysOnTopWindow = new SyncVisibleFrame();
                    alwaysOnTopWindow.setSize(2 * SIZE, SIZE);
                    alwaysOnTopWindow.setLocation(0, 0);
                    alwaysOnTopWindow.setVisible(true);

                    anotherWindow = new SyncVisibleFrame();
                    anotherWindow.setSize(2 * SIZE, SIZE);
                    anotherWindow.setLocation(SIZE, 0);
                    anotherWindow.setVisible(true);

                    robot.mouseMove(SIZE * 3 / 2, SIZE / 2);

                    setAlwaysOnTop(alwaysOnTopWindow, true);
                    anotherWindow.toFront();
                    waitForTimeout();
                    assert alwaysOnTopWindow.getMousePosition() != null;
                    assert anotherWindow.getMousePosition() == null;

                    setAlwaysOnTop(alwaysOnTopWindow, false);
                    assert alwaysOnTopWindow.getMousePosition() != null;
                    assert anotherWindow.getMousePosition() == null;

                    anotherWindow.toFront();
                    waitForTimeout();
                    assert alwaysOnTopWindow.getMousePosition() == null;
                    assert anotherWindow.getMousePosition() != null;
                } finally {
                    dispose(alwaysOnTopWindow);
                    dispose(anotherWindow);
                }
            }


            private void dispose(Window window) {
                if (window != null) {
                    window.dispose();
                }
                waitForTimeout();
            }


            private static void waitForTimeout() {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


            private void setAlwaysOnTop(Window window, boolean alwaysOnTop) {
                window.setAlwaysOnTop(alwaysOnTop);
                waitForTimeout();
            }

            private static class SyncVisibleFrame extends Frame {

                private final CountDownLatch latch = new CountDownLatch(1);

                @Override
                public void setVisible(boolean visible) {
                    super.setVisible(visible);

                    if (!visible) {
                        return;
                    }

                    try {
                        latch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    latch.countDown();
                }

                @Override
                public void dispose() {
                    super.dispose();
                    waitForTimeout();
                }

            }
        }

        The following testcase will fail due to this issue:
        api/java_awt/Window/indexTGF.html#AlwaysOnTop[normalStateRestored]

              azvegint Alexander Zvegintsev
              alfedoro Alexey Fedorov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: