1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.Component; 25 import java.awt.FlowLayout; 26 import java.awt.Frame; 27 import java.awt.Robot; 28 29 import javax.swing.JButton; 30 import javax.swing.SwingUtilities; 31 32 /** 33 * @test 34 * @bug 8071306 35 * @author Sergey Bylokhov 36 */ 37 public final class SetEnabledPerformance { 38 39 private static Frame frame; 40 41 private static void createAndShowGUI() { 42 frame = new Frame(); 43 frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0)); 44 frame.setSize(600, 600); 45 frame.setLocationRelativeTo(null); 46 for (int i = 1; i < 10001; ++i) { 47 frame.add(new JButton("Button " + i)); 48 } 49 frame.setVisible(true); 50 } 51 52 public static void main(final String[] args) throws Exception { 53 SwingUtilities.invokeAndWait(() -> createAndShowGUI()); 54 final Robot robot = new Robot(); 55 robot.waitForIdle(); 56 robot.mouseMove(frame.getX() + 15, frame.getY() + 300); 57 robot.waitForIdle(); 58 SwingUtilities.invokeAndWait(() -> { 59 long m = System.currentTimeMillis(); 60 for (final Component comp : frame.getComponents()) { 61 comp.setEnabled(false); 62 } 63 m = System.currentTimeMillis() - m; 64 System.err.println("Disabled in " + m + " ms"); 65 frame.dispose(); 66 // we should be much faster, but leaves 1000 for the slow systems 67 if (m > 1000) { 68 throw new RuntimeException("Too slow"); 69 } 70 }); 71 } 72 }