jdk/test/javax/swing/plaf/basic/BasicComboPopup/JComboBoxPopupLocation/JComboBoxPopupLocation.java
author mbaesken
Fri, 30 Jun 2017 16:32:18 +0200
changeset 47147 857d25fae728
parent 44346 fb0ddad3069d
permissions -rw-r--r--
8183286: Some java/awt and javax/swing tests miss headful jtreg keyword Reviewed-by: serb, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44346
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     1
/*
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     4
 *
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     8
 *
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    13
 * accompanied this code).
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    14
 *
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    18
 *
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    21
 * questions.
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    22
 */
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    23
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    24
import java.awt.EventQueue;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    25
import java.awt.FlowLayout;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    26
import java.awt.GraphicsConfiguration;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    27
import java.awt.GraphicsDevice;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    28
import java.awt.GraphicsEnvironment;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    29
import java.awt.Insets;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    30
import java.awt.Point;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    31
import java.awt.Rectangle;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    32
import java.awt.Robot;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    33
import java.awt.Toolkit;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    34
import java.awt.event.InputEvent;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    35
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    36
import javax.swing.JComboBox;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    37
import javax.swing.JFrame;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    38
import javax.swing.UIManager;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    39
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    40
/**
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    41
 * @test
47147
857d25fae728 8183286: Some java/awt and javax/swing tests miss headful jtreg keyword
mbaesken
parents: 44346
diff changeset
    42
 * @key headful
44346
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    43
 * @bug 8176448
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    44
 * @run main/timeout=600 JComboBoxPopupLocation
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    45
 */
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    46
public final class JComboBoxPopupLocation {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    47
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    48
    private static final int SIZE = 300;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    49
    public static final String PROPERTY_NAME = "JComboBox.isPopDown";
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    50
    private static volatile Robot robot;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    51
    private static volatile JComboBox<String> comboBox;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    52
    private static volatile JFrame frame;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    53
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    54
    public static void main(final String[] args) throws Exception {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    55
        robot = new Robot();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    56
        robot.setAutoDelay(100);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    57
        robot.setAutoWaitForIdle(true);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    58
        GraphicsEnvironment ge =
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    59
                GraphicsEnvironment.getLocalGraphicsEnvironment();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    60
        GraphicsDevice[] sds = ge.getScreenDevices();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    61
        UIManager.LookAndFeelInfo[] lookAndFeelArray =
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    62
                UIManager.getInstalledLookAndFeels();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    63
        for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    64
            System.setProperty(PROPERTY_NAME, "true");
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    65
            step(sds, lookAndFeelItem);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    66
            if (lookAndFeelItem.getClassName().contains("Aqua")) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    67
                System.setProperty(PROPERTY_NAME, "false");
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    68
                step(sds, lookAndFeelItem);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    69
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    70
        }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    71
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    72
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    73
    private static void step(GraphicsDevice[] sds,
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    74
                             UIManager.LookAndFeelInfo lookAndFeelItem)
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    75
            throws Exception {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    76
        UIManager.setLookAndFeel(lookAndFeelItem.getClassName());
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    77
        Point left = null;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    78
        for (final GraphicsDevice sd : sds) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    79
            GraphicsConfiguration gc = sd.getDefaultConfiguration();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    80
            Rectangle bounds = gc.getBounds();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    81
            if (left == null || left.x > bounds.x) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    82
                left = new Point(bounds.x, bounds.y + bounds.height / 2);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    83
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    84
            Point point = new Point(bounds.x, bounds.y);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    85
            Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    86
            while (point.y < bounds.y + bounds.height - insets.bottom - SIZE ) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    87
                while (point.x < bounds.x + bounds.width - insets.right - SIZE) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    88
                    try {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    89
                        EventQueue.invokeAndWait(() -> {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    90
                            setup(point);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    91
                        });
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    92
                        robot.waitForIdle();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    93
                        test(comboBox);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    94
                        robot.waitForIdle();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    95
                        validate(comboBox);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    96
                        robot.waitForIdle();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    97
                        point.translate(bounds.width / 5, 0);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    98
                    } finally {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
    99
                        dispose();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   100
                    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   101
                }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   102
                point.setLocation(bounds.x, point.y + bounds.height / 5);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   103
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   104
        }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   105
        if (left != null) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   106
            final Point finalLeft = left;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   107
            finalLeft.translate(-50, 0);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   108
            try {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   109
                EventQueue.invokeAndWait(() -> {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   110
                    setup(finalLeft);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   111
                });
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   112
                robot.waitForIdle();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   113
                test(comboBox);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   114
                robot.waitForIdle();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   115
                validate(comboBox);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   116
            } finally {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   117
                dispose();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   118
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   119
        }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   120
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   121
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   122
    private static void dispose() throws Exception {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   123
        EventQueue.invokeAndWait(() -> {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   124
            if (frame != null) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   125
                frame.dispose();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   126
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   127
        });
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   128
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   129
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   130
    private static void setup(final Point tmp) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   131
        comboBox = new JComboBox<>();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   132
        for (int i = 1; i < 7; i++) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   133
            comboBox.addItem("Long-long-long-long-long text in the item-" + i);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   134
        }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   135
        String property = System.getProperty(PROPERTY_NAME);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   136
        comboBox.putClientProperty(PROPERTY_NAME, Boolean.valueOf(property));
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   137
        frame = new JFrame();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   138
        frame.setAlwaysOnTop(true);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   139
        frame.setLayout(new FlowLayout());
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   140
        frame.add(comboBox);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   141
        frame.pack();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   142
        frame.setSize(frame.getWidth(), SIZE);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   143
        frame.setVisible(true);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   144
        frame.setLocation(tmp.x, tmp.y);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   145
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   146
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   147
    private static void test(final JComboBox comboBox) throws Exception {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   148
        Point pt = comboBox.getLocationOnScreen();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   149
        robot.mouseMove(pt.x + comboBox.getWidth() / 2,
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   150
                        pt.y + comboBox.getHeight() / 2);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   151
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   152
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   153
        int x = pt.x + comboBox.getWidth() / 2;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   154
        int y = pt.y + comboBox.getHeight() / 2 + 70;
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   155
        robot.mouseMove(x, y);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   156
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   157
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   158
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   159
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   160
    private static void validate(final JComboBox comboBox) throws Exception {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   161
        EventQueue.invokeAndWait(() -> {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   162
            if (comboBox.getSelectedIndex() == 0) {
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   163
                throw new RuntimeException();
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   164
            }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   165
        });
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   166
    }
fb0ddad3069d 8176448: [macos] Popups in JCombobox and Choice have incorrect location in multiscreen systems
serb
parents:
diff changeset
   167
}