10

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?

Pawel P.
  • 3,731
  • 4
  • 20
  • 20

2 Answers2

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.

Robin
  • 36,233
  • 5
  • 47
  • 99
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

java acm
  • 1,020
  • 12
  • 24
  • 1
    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) – Pawel P. Dec 14 '13 at 12:52
  • 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 ? – java acm Dec 14 '13 at 12:58
  • 1
    I use Intellij IDEA Community Edition 13.0. When I run this via cmd line there is no changes. – Pawel P. Dec 14 '13 at 13:43
  • 1
    No changes on jdk 7 u 25 – Pawel P. Dec 14 '13 at 13:50
  • 1
    It also happens on Windows 7. But only when "Show window contents while dragging" is active in system settings. – Pawel P. Dec 14 '13 at 13:57
  • 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.invokeLater – java acm Dec 14 '13 at 14:16
  • 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 http://stackoverflow.com/questions/8847083/swingutilities-invokelater-vs-eventqueue-invokelater – Pawel P. Dec 14 '13 at 14:37