Skip to content

Commit 9706c30

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents f72bf95 + c816464 commit 9706c30

File tree

2 files changed

+126
-9
lines changed

2 files changed

+126
-9
lines changed

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalRootPaneUI.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,31 @@
2525

2626
package javax.swing.plaf.metal;
2727

28-
import java.awt.event.*;
28+
import java.awt.Component;
29+
import java.awt.Container;
30+
import java.awt.Cursor;
31+
import java.awt.Dialog;
32+
import java.awt.Dimension;
33+
import java.awt.Frame;
34+
import java.awt.Insets;
35+
import java.awt.LayoutManager;
36+
import java.awt.LayoutManager2;
37+
import java.awt.Point;
38+
import java.awt.Rectangle;
39+
import java.awt.Toolkit;
40+
import java.awt.Window;
41+
import java.awt.event.InputEvent;
42+
import java.awt.event.MouseEvent;
2943
import java.beans.PropertyChangeEvent;
30-
import javax.swing.*;
31-
import javax.swing.event.*;
32-
import javax.swing.plaf.*;
33-
import javax.swing.plaf.basic.*;
34-
import java.awt.*;
44+
45+
import javax.swing.JComponent;
46+
import javax.swing.JLayeredPane;
47+
import javax.swing.JRootPane;
48+
import javax.swing.LookAndFeel;
49+
import javax.swing.SwingUtilities;
50+
import javax.swing.event.MouseInputListener;
51+
import javax.swing.plaf.ComponentUI;
52+
import javax.swing.plaf.basic.BasicRootPaneUI;
3553

3654
/**
3755
* Provides the metal look and feel implementation of <code>RootPaneUI</code>.
@@ -485,7 +503,7 @@ public Dimension preferredLayoutSize(Container parent) {
485503
}
486504

487505
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
488-
cpHeight + mbHeight + tpWidth + i.top + i.bottom);
506+
cpHeight + mbHeight + tpHeight + i.top + i.bottom);
489507
}
490508

491509
/**
@@ -536,7 +554,7 @@ public Dimension minimumLayoutSize(Container parent) {
536554
}
537555

538556
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
539-
cpHeight + mbHeight + tpWidth + i.top + i.bottom);
557+
cpHeight + mbHeight + tpHeight + i.top + i.bottom);
540558
}
541559

542560
/**
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2020, 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.Dimension;
26+
import java.awt.EventQueue;
27+
28+
import javax.swing.JFrame;
29+
import javax.swing.JLayeredPane;
30+
import javax.swing.JRootPane;
31+
import javax.swing.UIManager;
32+
import javax.swing.UnsupportedLookAndFeelException;
33+
34+
import static javax.swing.UIManager.getInstalledLookAndFeels;
35+
36+
/**
37+
* @test
38+
* @bug 4916923
39+
* @key headful
40+
* @summary MetalRootLayout does not correctly calculate minimumsize
41+
*/
42+
public final class RootPaneDecorationSize {
43+
44+
public static void main(String[] args) throws Exception {
45+
for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
46+
EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
47+
EventQueue.invokeAndWait(RootPaneDecorationSize::test);
48+
}
49+
}
50+
51+
private static void test() {
52+
JFrame frame = new JFrame();
53+
Dimension size;
54+
Dimension min;
55+
Dimension pref;
56+
try {
57+
// undecorated frame and decorated root pane usually used together
58+
frame.setUndecorated(true);
59+
frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
60+
// customize the current L&F (mimic custom L&F)
61+
JLayeredPane layeredPane = frame.getRootPane().getLayeredPane();
62+
for (Component comp : layeredPane.getComponents()) {
63+
comp.setMinimumSize(new Dimension(1000, 10));
64+
comp.setMaximumSize(new Dimension(1000, 10));
65+
comp.setPreferredSize(new Dimension(1000, 10));
66+
}
67+
frame.pack();
68+
size = frame.getSize();
69+
min = frame.getMinimumSize();
70+
pref = frame.getPreferredSize();
71+
} finally {
72+
frame.dispose();
73+
}
74+
System.err.println("\tsize = " + size);
75+
System.err.println("\tminimumSize = " + min);
76+
System.err.println("\tpreferredSize = " + pref);
77+
78+
// We cannot predict which size will be used by the current L&F
79+
// but based on customization above the height < 1000 and width > 1000
80+
if (size.height > 1000 || min.height > 1000 || pref.height > 1000) {
81+
throw new RuntimeException("The height too big");
82+
}
83+
if (size.width < 1000 || min.width < 1000 || pref.width < 1000) {
84+
throw new RuntimeException("The width too small");
85+
}
86+
}
87+
88+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
89+
try {
90+
System.err.println("LookAndFeel: " + laf.getClassName());
91+
UIManager.setLookAndFeel(laf.getClassName());
92+
} catch (UnsupportedLookAndFeelException ignored){
93+
System.err.println("Unsupported LookAndFeel: " + laf.getClassName());
94+
} catch (ClassNotFoundException | InstantiationException |
95+
IllegalAccessException e) {
96+
throw new RuntimeException(e);
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)