Path: blob/master/test/jdk/java/awt/Focus/RemoveAfterRequest/RemoveAfterRequest.java
41152 views
/*1* Copyright (c) 2009, 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*/2223/*24@test25@key headful26@bug 641140627@summary Components automatically transfer focus on removal, even if developer requests focus elsewhere first28@author oleg.sukhodolsky, anton.tarasov: area=awt.focus29@library ../../regtesthelpers30@build Util31@run main RemoveAfterRequest32*/3334/**35* RemoveAfterRequest.java36*37* summary: Components automatically transfer focus on removal, even if developer requests focus elsewhere first38*/3940import java.awt.*;41import java.awt.event.*;42import test.java.awt.regtesthelpers.Util;4344public class RemoveAfterRequest {45final static Frame frame = new Frame("test frame");46final static Button btn1 = new Button("btn1");47final static Button btn2 = new Button("btn2");48final static Button btn3 = new Button("btn3");4950public static void main(String[] args) {51frame.setLayout(new GridLayout(3, 1));52frame.add(btn1);53frame.add(btn2);54frame.add(btn3);55frame.pack();56frame.setVisible(true);5758Util.waitForIdle(null);5960if (!btn1.hasFocus()) {61btn1.requestFocus();62Util.waitForIdle(null);63if (!btn1.hasFocus()) {64throw new TestErrorException("couldn't focus " + btn1);65}66}6768if (!Util.trackFocusGained(btn3, new Runnable() {69public void run() {70btn3.requestFocus();71frame.remove(btn1);72frame.invalidate();73frame.validate();74frame.repaint();75}76}, 2000, true))77{78throw new TestFailedException("focus request on removal failed");79}8081System.out.println("Test passed.");82}83}8485/**86* Thrown when the behavior being verified is found wrong.87*/88class TestFailedException extends RuntimeException {89TestFailedException(String msg) {90super("Test failed: " + msg);91}92}9394/**95* Thrown when an error not related to the behavior being verified is encountered.96*/97class TestErrorException extends RuntimeException {98TestErrorException(String msg) {99super("Unexpected error: " + msg);100}101}102103104105