Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_AWT.java
38828 views
/*1* Copyright (c) 2011, 2013, 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@bug 674152626@summary KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components27@library ../../regtesthelpers28@build Sysout29@author Andrei Dmitriev : area=awt-focus30@run main DefaultPolicyChange_AWT31*/3233import java.awt.*;34import test.java.awt.regtesthelpers.Sysout;3536public class DefaultPolicyChange_AWT {37public static void main(String []s) {38DefaultPolicyChange_AWT.runTestAWT();39}4041private static void runTestAWT(){42KeyboardFocusManager currentKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();43FocusTraversalPolicy defaultFTP = currentKFM.getDefaultFocusTraversalPolicy();44ContainerOrderFocusTraversalPolicy newFTP = new ContainerOrderFocusTraversalPolicy();4546Frame frame = new Frame();47Window window = new Window(frame);4849FocusTraversalPolicy resultFTP = window.getFocusTraversalPolicy();50Sysout.println("FocusTraversalPolicy on window = " + resultFTP);51/**52* Note: this call doesn't affect already created components as they have53* their policy initialized. Only new components will use this policy as54* their default policy.55**/56Sysout.println("Now will set another policy.");57currentKFM.setDefaultFocusTraversalPolicy(newFTP);58resultFTP = window.getFocusTraversalPolicy();59if (!resultFTP.equals(defaultFTP)) {60Sysout.println("Failure! FocusTraversalPolicy should not change");61Sysout.println("Was: " + defaultFTP);62Sysout.println("Become: " + resultFTP);63throw new RuntimeException("Failure! FocusTraversalPolicy should not change");64}65}66}676869