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.

Reviewed-by: aivanov, dmarkov, azvegint
  • Loading branch information
Harshitha Onkar authored and dmarkov20 committed Jun 14, 2022
1 parent 0f58097 commit bbaeacb
Show file tree
Hide file tree
Showing 2 changed files with 108 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 @@ -1391,6 +1390,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 @@ -1414,17 +1416,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
101 changes: 101 additions & 0 deletions test/jdk/java/awt/Frame/AwtFramePackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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
* @requires (os.family == "windows")
* @summary Tests whether insets are calculated correctly on Windows
* for AWT Frame by checking the actual and expected/preferred frame sizes.
* @run main/othervm -Dsun.java2d.uiScale=1 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();
}
}
}

1 comment on commit bbaeacb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.