# HG changeset patch # User mhalder # Date 1520414686 -19800 # Node ID e0b025915be8a2ea2e42fa60796171d4b285f98c # Parent d432d559a343ea8d27570b60eadf137b7b209995 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default Reviewed-by: serb, kaddepalli diff -r d432d559a343 -r e0b025915be8 src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Mar 07 18:20:09 2018 +0530 +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Mar 07 14:54:46 2018 +0530 @@ -382,8 +382,6 @@ styleBits = SET(styleBits, RESIZABLE, resizable); if (!resizable) { styleBits = SET(styleBits, ZOOMABLE, false); - } else { - setCanFullscreen(true); } } @@ -677,6 +675,15 @@ // Manage the extended state when showing if (visible) { + /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the + Frame or Dialog is resizable. + **/ + final boolean resizable = (target instanceof Frame) ? ((Frame)target).isResizable() : + ((target instanceof Dialog) ? ((Dialog)target).isResizable() : false); + if (resizable) { + setCanFullscreen(true); + } + // Apply the extended state as expected in shared code if (target instanceof Frame) { if (!wasMaximized && isMaximized()) { diff -r d432d559a343 -r e0b025915be8 test/jdk/java/awt/FullScreen/AllFramesMaximize/AllFramesMaximize.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/awt/FullScreen/AllFramesMaximize/AllFramesMaximize.java Wed Mar 07 14:54:46 2018 +0530 @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8190767 + * @key headful + * @requires os.family == "mac" + * @summary If JFrame is maximized on OS X, all new JFrames will be maximized by default + * @compile AllFramesMaximize.java + * @run main/manual AllFramesMaximize + */ + +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class AllFramesMaximize { + private static JButton passButton; + private static JButton failButton; + private static JTextArea instructions; + private static JFrame mainFrame; + private static JFrame instructionFrame; + public static boolean isProgInterruption = false; + static Thread mainThread = null; + static int sleepTime = 300000; + + public static void createAndShowJFrame() { + passButton = new JButton("Pass"); + passButton.setEnabled(true); + + failButton = new JButton("Fail"); + failButton.setEnabled(true); + + instructions = new JTextArea(8, 30); + instructions.setText(" This is a manual test\n\n" + + " 1) Click on the maximize button, JFrame will enter fullscreen\n" + + " 2) Click anywhere on the JFrame\n" + + " 3) Press Pass if new JFrame didn't open in fullscreen,\n" + + " 4) Press Fail if new JFrame opened in fullscreen"); + + instructionFrame = new JFrame("Test Instructions"); + instructionFrame.setLocationRelativeTo(null); + instructionFrame.add(passButton); + instructionFrame.add(failButton); + instructionFrame.add(instructions); + instructionFrame.setSize(200,200); + instructionFrame.setLayout(new FlowLayout()); + instructionFrame.pack(); + instructionFrame.setVisible(true); + + passButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + dispose(); + isProgInterruption = true; + mainThread.interrupt(); + } + }); + + failButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + dispose(); + isProgInterruption = true; + mainThread.interrupt(); + throw new RuntimeException("New JFrame opened on a new window!"); + } + }); + + mainFrame = new JFrame(); + JButton button = new JButton("Open Frame"); + mainFrame.getContentPane().add(button); + button.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + JFrame f = new JFrame(); + f.setSize(400, 400); + f.setVisible(true); + } + }); + mainFrame.setSize(500, 500); + mainFrame.setVisible(true); + } + + private static void dispose() { + mainFrame.dispose(); + instructionFrame.dispose(); + } + + public static void main(String[] args) throws Exception { + mainThread = Thread.currentThread(); + SwingUtilities.invokeAndWait(AllFramesMaximize::createAndShowJFrame); + + try { + mainThread.sleep(sleepTime); + } catch (InterruptedException e) { + if (!isProgInterruption) { + throw e; + } + } finally { + SwingUtilities.invokeAndWait(AllFramesMaximize::dispose); + } + + if (!isProgInterruption) { + throw new RuntimeException("Timed out after " + sleepTime / 1000 + + " seconds"); + } + } +} +