From 3c09c2cd2d8e93844f366a3c9e2e3790ecc0d029 Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Fri, 20 Mar 2026 02:38:41 +0000 Subject: [PATCH] 8267961: JInternalFrame.getNormalBounds() returns normalBounds when maximized state is false instead of bounds Reviewed-by: tr, dnguyen --- .../classes/javax/swing/JInternalFrame.java | 6 ++ .../TestNonMaximizedNormalBounds.java | 73 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 test/jdk/javax/swing/JInternalFrame/TestNonMaximizedNormalBounds.java diff --git a/src/java.desktop/share/classes/javax/swing/JInternalFrame.java b/src/java.desktop/share/classes/javax/swing/JInternalFrame.java index f3295cd6ad8..dec53d29e75 100644 --- a/src/java.desktop/share/classes/javax/swing/JInternalFrame.java +++ b/src/java.desktop/share/classes/javax/swing/JInternalFrame.java @@ -987,6 +987,9 @@ public class JInternalFrame extends JComponent implements = "Indicates whether this internal frame is maximized.") public void setMaximum(boolean b) throws PropertyVetoException { if (isMaximum == b) { + if (!b) { + normalBounds = null; + } return; } @@ -998,6 +1001,9 @@ public class JInternalFrame extends JComponent implements get it wrong... See, for example, getNormalBounds() */ isMaximum = b; firePropertyChange(IS_MAXIMUM_PROPERTY, oldValue, newValue); + if (!b) { + normalBounds = null; + } } /** diff --git a/test/jdk/javax/swing/JInternalFrame/TestNonMaximizedNormalBounds.java b/test/jdk/javax/swing/JInternalFrame/TestNonMaximizedNormalBounds.java new file mode 100644 index 00000000000..67faeeb5bb1 --- /dev/null +++ b/test/jdk/javax/swing/JInternalFrame/TestNonMaximizedNormalBounds.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2026, 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 + * @key headful + * @bug 8267961 + * @summary Verify JInternalFrame.getNormalBounds() + * returns getBounds() value in non-maximized state + * @run main TestNonMaximizedNormalBounds + */ + +import java.awt.Rectangle; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.SwingUtilities; +import java.beans.PropertyVetoException; + +public class TestNonMaximizedNormalBounds { + + private static volatile Rectangle bounds; + private static volatile Rectangle normalBounds; + private static JInternalFrame jif; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(() -> { + Rectangle bounds = new Rectangle(96, 97, 98, 99); + Rectangle nbounds = new Rectangle(196, 197, 198, 199); + JDesktopPane p = new JDesktopPane(); + jif = new JInternalFrame(); + p.add(jif); + jif.setBounds(bounds); + jif.setNormalBounds(nbounds); + }); + Thread.sleep(100); + SwingUtilities.invokeAndWait(() -> { + try { + jif.setMaximum(false); + } catch (PropertyVetoException e) { + throw new RuntimeException(e); + } + }); + Thread.sleep(100); + SwingUtilities.invokeAndWait(() -> { + normalBounds = jif.getNormalBounds(); + bounds = jif.getBounds(); + }); + if (!normalBounds.equals(bounds)) { + System.out.println("normalBounds " + normalBounds + " getBounds " + bounds); + throw new RuntimeException("normalBounds not equal to getBounds in non-maximized state"); + } + } +}