JRE-938 [windows] Frame.setMaximizedBounds not hidpi-aware

(cherry picked from commit cc97899923320e1fa17f5e44975c4a0f0ba51014)
(cherry picked from commit ccfe65be7f)
This commit is contained in:
Anton Tarasov
2018-09-05 16:34:13 +03:00
committed by alexey.ushakov@jetbrains.com
parent 3eb51d71fa
commit 388b3d1e2b
2 changed files with 58 additions and 0 deletions

View File

@@ -1475,6 +1475,10 @@ void AwtFrame::_SetMaximizedBounds(void *param)
if (::IsWindow(f->GetHWnd()))
{
DASSERT(!::IsBadReadPtr(f, sizeof(AwtFrame)));
x = f->ScaleUpAbsX(x);
y = f->ScaleUpAbsY(y);
width = f->ScaleUpX(width);
height = f->ScaleUpY(height);
f->SetMaximizedBounds(x, y, width, height);
}
ret:

View File

@@ -0,0 +1,54 @@
import javax.swing.*;
import java.awt.*;
import sun.awt.SunToolkit;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CountDownLatch;
/* @test
* bug JRE-938
* @summary Tests that Frame.setMaximizedBounds meets HiDPI.
* @author Anton Tarasov
* @requires (os.family == "windows")
* @modules java.desktop/sun.awt
* @run main/othervm -Dsun.java2d.uiScale.enabled=true
* -Dsun.java2d.uiScale=2
* SetMaximizedBoundsTest
*/
public class SetMaximizedBoundsTest {
private static volatile JFrame frame;
private static final Rectangle MAX_BOUNDS = new Rectangle(100, 100, 500, 500);
private static volatile Rectangle testBounds;
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
EventQueue.invokeAndWait(SetMaximizedBoundsTest::show);
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
EventQueue.invokeAndWait(SetMaximizedBoundsTest::maximize);
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
EventQueue.invokeAndWait(SetMaximizedBoundsTest::test);
if (!MAX_BOUNDS.equals(testBounds)) {
throw new RuntimeException("Test FAILED: bad bounds " + testBounds);
}
System.out.println("Test PASSED");
}
private static void show() {
frame = new JFrame("frame");
frame.setBounds(200, 200, 200, 200);
frame.setVisible(true);
}
private static void maximize() {
frame.setMaximizedBounds(MAX_BOUNDS);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
private static void test() {
testBounds = frame.getBounds();
frame.dispose();
}
}