You can resize JFrame with mouse dragging in several ways:
It appears to be a bug in the Windows implementation of Java. (I am also using Windows 7 and JDK7.)
When Windows decides to change the height of the window, a COMPONENT_MOVED
event is received by Window, but no COMPONENT_RESIZED
event is received.
Inside the Windows class, the non-public method dispatchEventImpl()
will respond to COMPONENT_RESIZED
events by calling invalidate()
and validate()
, but it will ignore COMPONENT_MOVED
events.
Here is a brute-force method of making the window re-validate itself after such an event. This may occasionally make the window re-validate in other situations, but not very often since the Window class itself is doing re-validation after every COMPONENT_RESIZED
event, and the reported bug only happens when the window is being actively resized by the user.
masterWindow.addComponentListener(new ComponentAdapter() {
private int oldWidth = 0;
private int oldHeight = 0;
@Override
public void componentResized(ComponentEvent e) {
oldWidth = masterWindow.getWidth();
oldHeight = masterWindow.getHeight();
}
@Override
public void componentMoved(ComponentEvent e) {
if (masterWindow.getWidth() != oldWidth || masterWindow.getHeight() != oldHeight) {
masterWindow.invalidate();
masterWindow.validate();
}
oldWidth = masterWindow.getWidth();
oldHeight = masterWindow.getHeight();
}
});