JFrame freezes on Windows 8.1 when resized
Asked Answered
H

2

11

Also posted on coderanch.com.

import javax.swing.*;

public class Tmp {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame();
                frame.setSize(200, 200);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new JTextField());
                frame.setVisible(true);
            }
        });
    }
}

A problem regarding resizing this JFrame.

This is how it looks by default right after program starts:

enter image description here

When I try to resize it like shown on a picture and move a mouse pointer to the top of a screen (like on picture below) I see this:

enter image description here

When I release the mouse the frame is resized but unresponsive. And there is a black space on it. This is how it looks:

enter image description here

This happens on Windows 8.1 and java 1.7.0_45 (it also happens on Windows 7).
The problem does not occur when using other ways of resizing a frame in Windows.
It only happens when "Show window contents while dragging" is active in system settings.
Why is it happening?
How can this be fixed?

Hotel answered 14/12, 2013 at 12:25 Comment(7)
Try changing frame.setVisible(true); to frame.pack(); frame.setVisible(true);..Stribling
@AndrewThompson no changes.Hotel
I'm Blue (fom one of pre_relleases) user but I'm never see thatBacchus
Hey, did You manage to find an answer for this? How did You fix it?Radish
Netbeans 7.4 itself having the same issue with windows 7 dropbox.com/s/6u3zwro8bjdmrc1/…Devilment
try run the program with the JVM options: -Dsun.java2d.noddraw=true -Dsun.java2d.dpiaware=trueAmbala
Are you using unity window manager?Lindeman
V
4

This sounds a lot like the bug reported here. Supposed to be fixed in JDK8 and 9, and according to the issue tracker the bug fix is backported into version 7u80.

Verbose answered 19/9, 2014 at 16:56 Comment(0)
A
0

i have windows 7 with jdk1.7.0_25 and your code worked as fine for me
i have 3 solution :
1-i think Oracle is wrong in update of 45 you can replaced 45 with 25
2-any graphical user interface in java uses from OS and maybe windows 8 not compatible with java 7 yet
3-you can add a listener for frame resize and call repaint(); in body of listener or set size to actual size
also you can try to using setUndecorated(true) and custom mouse listener which implements frame resize

Anima answered 14/12, 2013 at 12:45 Comment(7)
I don't have access to Win 7 machine right now so I can't check this. I added listener on frame resize and called repaint in it. Didn't help. What is worse, it seems that the listener wasn't fired at all during resize! (I mean in this part after mouse release and frame spanning over full height of the screen)Hotel
is strange !! you can downloaded jdk 7 u 25 and try again. what is your IDE ? and how to run this code ? run on IDE or in CMD ?Anima
I use Intellij IDEA Community Edition 13.0. When I run this via cmd line there is no changes.Hotel
No changes on jdk 7 u 25Hotel
It also happens on Windows 7. But only when "Show window contents while dragging" is active in system settings.Hotel
if you not changes on jdk7u25 main problem is OS , because gui component powered by OS layer . i run your code in win7 and not problem with it . try this replace SwingUtilities.invokeLater with EventQueue.invokeLaterAnima
Do you have "Show window contents while dragging" enabled in your system? If this is on the error is present regardles of OS version or jdk version (checked in every possible combination of Win8, Win7, jdk1.6_26, jdk1.7_25, jdk1.7.45"). And SwingUtilities.invokeLater is the same as EventQueue.invokeLater #8847583Hotel

© 2022 - 2024 — McMap. All rights reserved.