Skip to content

Commit ce1602d

Browse files
committed
8265586: [windows] last button is not shown in AWT Frame with BorderLayout and MenuBar set.
8288993: Make AwtFramePackTest generic by removing @requires tag Backport-of: d2045f9cfa88cb8bea58e5476f5917464f966028
1 parent 70862e0 commit ce1602d

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

src/java.desktop/windows/native/libawt/windows/awt_Window.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525

2626
#include "awt.h"
27-
2827
#include <jlong.h>
2928

3029
#include "awt_Component.h"
@@ -1396,6 +1395,9 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
13961395
RECT inside;
13971396
int extraBottomInsets = 0;
13981397

1398+
// extra padded border for captioned windows
1399+
int extraPaddedBorderInsets = ::GetSystemMetrics(SM_CXPADDEDBORDER);
1400+
13991401
::GetClientRect(GetHWnd(), &inside);
14001402
::GetWindowRect(GetHWnd(), &outside);
14011403

@@ -1419,17 +1421,15 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
14191421
LONG style = GetStyle();
14201422
if (style & WS_THICKFRAME) {
14211423
m_insets.left = m_insets.right =
1422-
::GetSystemMetrics(SM_CXSIZEFRAME);
1424+
::GetSystemMetrics(SM_CXSIZEFRAME) + extraPaddedBorderInsets;
14231425
m_insets.top = m_insets.bottom =
1424-
::GetSystemMetrics(SM_CYSIZEFRAME);
1426+
::GetSystemMetrics(SM_CYSIZEFRAME) + extraPaddedBorderInsets;
14251427
} else {
14261428
m_insets.left = m_insets.right =
1427-
::GetSystemMetrics(SM_CXDLGFRAME);
1429+
::GetSystemMetrics(SM_CXDLGFRAME) + extraPaddedBorderInsets;
14281430
m_insets.top = m_insets.bottom =
1429-
::GetSystemMetrics(SM_CYDLGFRAME);
1431+
::GetSystemMetrics(SM_CYDLGFRAME) + extraPaddedBorderInsets;
14301432
}
1431-
1432-
14331433
/* Add in title. */
14341434
m_insets.top += ::GetSystemMetrics(SM_CYCAPTION);
14351435
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2022, 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.AWTException;
25+
import java.awt.BorderLayout;
26+
import java.awt.Button;
27+
import java.awt.Dimension;
28+
import java.awt.Frame;
29+
import java.awt.Menu;
30+
import java.awt.MenuBar;
31+
import java.awt.Panel;
32+
import java.awt.Robot;
33+
import java.awt.image.BufferedImage;
34+
import java.io.File;
35+
import java.io.IOException;
36+
import javax.imageio.ImageIO;
37+
38+
/*
39+
* @test
40+
* @bug 8265586
41+
* @key headful
42+
* @summary Tests whether insets are calculated correctly on Windows
43+
* for AWT Frame by checking the actual and expected/preferred frame sizes.
44+
* @run main AwtFramePackTest
45+
*/
46+
47+
public class AwtFramePackTest {
48+
49+
private static Frame frame;
50+
private static Robot robot;
51+
52+
public static void main(String[] args) throws AWTException {
53+
try {
54+
robot = new Robot();
55+
robot.setAutoDelay(300);
56+
57+
frame = new Frame();
58+
frame.setLayout(new BorderLayout());
59+
60+
Panel panel = new Panel();
61+
panel.add(new Button("Panel Button B1"));
62+
panel.add(new Button("Panel Button B2"));
63+
frame.add(panel, BorderLayout.CENTER);
64+
65+
MenuBar mb = new MenuBar();
66+
Menu m = new Menu("Menu");
67+
mb.add(m);
68+
frame.setMenuBar(mb);
69+
70+
frame.pack();
71+
frame.setVisible(true);
72+
73+
robot.delay(500);
74+
robot.waitForIdle();
75+
76+
Dimension actualFrameSize = frame.getSize();
77+
Dimension expectedFrameSize = frame.getPreferredSize();
78+
79+
if (!actualFrameSize.equals(expectedFrameSize)) {
80+
System.out.println("Expected frame size: "+ expectedFrameSize);
81+
System.out.println("Actual frame size: "+ actualFrameSize);
82+
saveScreenCapture();
83+
throw new RuntimeException("Expected and Actual frame size" +
84+
" are different. frame.pack() does not work!!");
85+
}
86+
} finally {
87+
frame.dispose();
88+
}
89+
}
90+
91+
// for debugging purpose, saves screen capture when test fails.
92+
private static void saveScreenCapture() {
93+
BufferedImage image = robot.createScreenCapture(frame.getBounds());
94+
try {
95+
ImageIO.write(image,"png", new File("Frame.png"));
96+
} catch (IOException e) {
97+
e.printStackTrace();
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)