Path: blob/master/test/jdk/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_AWT.java
41153 views
/*1* Copyright (c) 2011, 2018, 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 674152627@summary KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components28@library ../../regtesthelpers29@build Sysout30@author Andrei Dmitriev : area=awt-focus31@run main DefaultPolicyChange_AWT32*/3334import java.awt.*;35import test.java.awt.regtesthelpers.Sysout;3637public class DefaultPolicyChange_AWT {38public static void main(String []s) {39DefaultPolicyChange_AWT.runTestAWT();40}4142private static void runTestAWT(){43KeyboardFocusManager currentKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();44FocusTraversalPolicy defaultFTP = currentKFM.getDefaultFocusTraversalPolicy();45ContainerOrderFocusTraversalPolicy newFTP = new ContainerOrderFocusTraversalPolicy();4647Frame frame = new Frame();48Window window = new Window(frame);4950FocusTraversalPolicy resultFTP = window.getFocusTraversalPolicy();51System.out.println("FocusTraversalPolicy on window = " + resultFTP);52/**53* Note: this call doesn't affect already created components as they have54* their policy initialized. Only new components will use this policy as55* their default policy.56**/57System.out.println("Now will set another policy.");58currentKFM.setDefaultFocusTraversalPolicy(newFTP);59resultFTP = window.getFocusTraversalPolicy();60if (!resultFTP.equals(defaultFTP)) {61System.out.println("Failure! FocusTraversalPolicy should not change");62System.out.println("Was: " + defaultFTP);63System.out.println("Become: " + resultFTP);64throw new RuntimeException("Failure! FocusTraversalPolicy should not change");65}66}67}686970