Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Dimension;24import java.awt.Point;25import java.awt.Robot;26import java.awt.event.ActionEvent;27import java.awt.event.ActionListener;28import javax.swing.BoxLayout;29import javax.swing.JComboBox;30import javax.swing.JFrame;31import javax.swing.SwingUtilities;32import test.java.awt.regtesthelpers.Util;333435/**36* AWT/Swing overlapping test for {@link javax.swing.JCombobox } component.37* <p>This test creates combobox and test if heavyweight component is drawn correctly then dropdown is shown.38* <p>See base class for details.39*/40/*41* @test42* @key headful43* @summary Overlapping test for javax.swing.JScrollPane44* @author [email protected]: area=awt.mixing45* @library /java/awt/patchlib ../../regtesthelpers46* @modules java.desktop/sun.awt47* java.desktop/java.awt.peer48* @build java.desktop/java.awt.Helper49* @build Util50* @run main JComboBoxOverlapping51*/52public class JComboBoxOverlapping extends OverlappingTestBase {5354private boolean lwClicked = false;55private Point loc;56private Point loc2;57private JComboBox cb;58private JFrame frame;5960{testEmbeddedFrame = true;}6162protected void prepareControls() {63frame = new JFrame("Mixing : Dropdown Overlapping test");64frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));65frame.setSize(200, 200);66frame.setVisible(true);6768cb = new JComboBox(petStrings);69cb.setPreferredSize(new Dimension(frame.getContentPane().getWidth(), 20));70cb.addActionListener(new ActionListener() {7172public void actionPerformed(ActionEvent e) {73if (e.getSource() == cb) {74lwClicked = true;75}76}77});7879frame.add(cb);80propagateAWTControls(frame);81frame.setVisible(true);82}8384@Override85protected boolean performTest() {86// run robot87Robot robot = Util.createRobot();88robot.setAutoDelay(ROBOT_DELAY);89robot.waitForIdle();90robot.delay(200);91try {92SwingUtilities.invokeAndWait(() -> {93loc = cb.getLocationOnScreen();94loc2 = frame.getContentPane().getLocationOnScreen();95});96} catch (Exception e) {97throw new RuntimeException(e);98}99100loc2.translate(75, 75);101pixelPreCheck(robot, loc2, currentAwtControl);102103loc.translate(3, 3);104clickAndBlink(robot, loc, false);105106clickAndBlink(robot, loc2, false);107108return lwClicked;109}110111// this strange plumbing stuff is required due to "Standard Test Machinery" in base class112public static void main(String args[]) throws InterruptedException {113instance = new JComboBoxOverlapping();114OverlappingTestBase.doMain(args);115}116}117118119