1 /* 2 * Copyright (c) 2017, 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 /** 25 * @test 8190767 26 * @key headful 27 * @summary If JFrame is maximized on OS X, all new JFrames will be maximized by default 28 * @compile AllFramesMaximize.java 29 * @run main/manual AllFramesMaximize 30 */ 31 32 import javax.swing.JFrame; 33 import javax.swing.JButton; 34 import javax.swing.JTextArea; 35 import javax.swing.SwingUtilities; 36 import java.awt.FlowLayout; 37 import java.awt.event.ActionEvent; 38 import java.awt.event.ActionListener; 39 40 41 public class AllFramesMaximize { 42 private static JButton passButton; 43 private static JButton failButton; 44 private static JTextArea instructions; 45 private static JFrame mainFrame; 46 private static JFrame instructionFrame; 47 public static boolean isProgInterruption = false; 48 static Thread mainThread = null; 49 static int sleepTime = 300000; 50 51 public AllFramesMaximize() { 52 passButton = new JButton("Pass"); 53 passButton.setEnabled(true); 54 55 failButton = new JButton("Fail"); 56 failButton.setEnabled(true); 57 58 instructions = new JTextArea(8, 30); 59 instructions.setText(" This is a manual test\n\n" + 60 " 1) Click on the maximize button, JFrame will enter fullscreen\n" + 61 " 2) Click anywhere on the JFrame\n" + 62 " 3) Press Pass if new JFrame didn't open in fullscreen,\n" + 63 " 4) Press Fail if new JFrame opened in fullscreen"); 64 65 instructionFrame = new JFrame("Test Instructions"); 66 instructionFrame.setLocationRelativeTo(null); 67 instructionFrame.add(passButton); 68 instructionFrame.add(failButton); 69 instructionFrame.add(instructions); 70 instructionFrame.setSize(200,200); 71 instructionFrame.setLayout(new FlowLayout()); 72 instructionFrame.pack(); 73 instructionFrame.setVisible(true); 74 75 passButton.addActionListener(new ActionListener() { 76 @Override 77 public void actionPerformed(ActionEvent ae) { 78 dispose(); 79 isProgInterruption = true; 80 mainThread.interrupt(); 81 } 82 }); 83 84 failButton.addActionListener(new ActionListener() { 85 @Override 86 public void actionPerformed(ActionEvent ae) { 87 dispose(); 88 isProgInterruption = true; 89 mainThread.interrupt(); 90 throw new RuntimeException("New JFrame opened on a new window!"); 91 } 92 }); 93 } 94 95 public static void createAndShowJFrame() { 96 mainFrame = new JFrame(); 97 JButton button = new JButton("Open Frame"); 98 mainFrame.getContentPane().add(button); 99 button.addActionListener( 100 new ActionListener() { 101 public void actionPerformed(ActionEvent e) { 102 JFrame f = new JFrame(); 103 f.setSize(400, 400); 104 f.setVisible(true); 105 } 106 }); 107 mainFrame.setSize(500, 500); 108 mainFrame.setVisible(true); 109 } 110 111 private static void dispose() { 112 mainFrame.dispose(); 113 instructionFrame.dispose(); 114 } 115 116 public static void main(String[] args) throws Exception { 117 mainThread = Thread.currentThread(); 118 AllFramesMaximize test = new AllFramesMaximize(); 119 SwingUtilities.invokeLater(AllFramesMaximize::createAndShowJFrame); 120 121 try { 122 mainThread.sleep(sleepTime); 123 } catch (InterruptedException e) { 124 if (!isProgInterruption) { 125 throw e; 126 } 127 } finally { 128 test.dispose(); 129 } 130 131 if (!isProgInterruption) { 132 throw new RuntimeException("Timed out after " + sleepTime / 1000 133 + " seconds"); 134 } 135 } 136 } 137