Skip to content

Commit

Permalink
8265586: [windows] last button is not shown in AWT Frame with BorderL…
Browse files Browse the repository at this point in the history
…ayout and MenuBar set.

8288993: Make AwtFramePackTest generic by removing @requires tag

Backport-of: bbaeacb597a8acc2c88793a6231c53ea0453f4d4
  • Loading branch information
GoeLin committed Sep 20, 2023
1 parent f3ee6ea commit d2045f9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/java.desktop/windows/native/libawt/windows/awt_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

#include "awt.h"

#include <jlong.h>

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

// extra padded border for captioned windows
int extraPaddedBorderInsets = ::GetSystemMetrics(SM_CXPADDEDBORDER);

::GetClientRect(GetHWnd(), &inside);
::GetWindowRect(GetHWnd(), &outside);

Expand All @@ -1419,17 +1421,15 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
LONG style = GetStyle();
if (style & WS_THICKFRAME) {
m_insets.left = m_insets.right =
::GetSystemMetrics(SM_CXSIZEFRAME);
::GetSystemMetrics(SM_CXSIZEFRAME) + extraPaddedBorderInsets;
m_insets.top = m_insets.bottom =
::GetSystemMetrics(SM_CYSIZEFRAME);
::GetSystemMetrics(SM_CYSIZEFRAME) + extraPaddedBorderInsets;
} else {
m_insets.left = m_insets.right =
::GetSystemMetrics(SM_CXDLGFRAME);
::GetSystemMetrics(SM_CXDLGFRAME) + extraPaddedBorderInsets;
m_insets.top = m_insets.bottom =
::GetSystemMetrics(SM_CYDLGFRAME);
::GetSystemMetrics(SM_CYDLGFRAME) + extraPaddedBorderInsets;
}


/* Add in title. */
m_insets.top += ::GetSystemMetrics(SM_CYCAPTION);
}
Expand Down
100 changes: 100 additions & 0 deletions test/jdk/java/awt/Frame/AwtFramePackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2022, 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.
*/

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.Panel;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/*
* @test
* @bug 8265586
* @key headful
* @summary Tests whether insets are calculated correctly on Windows
* for AWT Frame by checking the actual and expected/preferred frame sizes.
* @run main AwtFramePackTest
*/

public class AwtFramePackTest {

private static Frame frame;
private static Robot robot;

public static void main(String[] args) throws AWTException {
try {
robot = new Robot();
robot.setAutoDelay(300);

frame = new Frame();
frame.setLayout(new BorderLayout());

Panel panel = new Panel();
panel.add(new Button("Panel Button B1"));
panel.add(new Button("Panel Button B2"));
frame.add(panel, BorderLayout.CENTER);

MenuBar mb = new MenuBar();
Menu m = new Menu("Menu");
mb.add(m);
frame.setMenuBar(mb);

frame.pack();
frame.setVisible(true);

robot.delay(500);
robot.waitForIdle();

Dimension actualFrameSize = frame.getSize();
Dimension expectedFrameSize = frame.getPreferredSize();

if (!actualFrameSize.equals(expectedFrameSize)) {
System.out.println("Expected frame size: "+ expectedFrameSize);
System.out.println("Actual frame size: "+ actualFrameSize);
saveScreenCapture();
throw new RuntimeException("Expected and Actual frame size" +
" are different. frame.pack() does not work!!");
}
} finally {
frame.dispose();
}
}

// for debugging purpose, saves screen capture when test fails.
private static void saveScreenCapture() {
BufferedImage image = robot.createScreenCapture(frame.getBounds());
try {
ImageIO.write(image,"png", new File("Frame.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}

3 comments on commit d2045f9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member Author

@GoeLin GoeLin commented on d2045f9 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d2045f9 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-d2045f9c in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d2045f9c from the openjdk/jdk17u-dev repository.

The commit being backported was authored by Goetz Lindenmaier on 20 Sep 2023 and had no reviewers.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git GoeLin-backport-d2045f9c:GoeLin-backport-d2045f9c
$ git checkout GoeLin-backport-d2045f9c
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git GoeLin-backport-d2045f9c

Please sign in to comment.