Re: JFrame Resize Issues



Oh boy, um... providing compilable source code for this problem may
span quite a few pages. I'll start by explaining what I mean by
"fight".

When I have the frames undecorated, I believe the Java VM uses
Windows(r) own Window Manager (Windows2000/XP is what I am developing
on). In this case, the componentResized() event is issued when the
user has completed resizing the frame. However, when I switch to
Decorated frames, the Java VM issues componentResized() while the user
is still resizing (like every couple of pixels that they move it).

When a resize is called, I basically call a function: resizeVideo()
which checks to see if aspect ratio is enabled and if it is resizes the
window based on the aspect ratio.

if ( ControlAspect.getText().equals( "Aspect Off" ) ) {
if ( newHeight != oldHeight || newWidth != oldWidth ) {
// Keep aspect ratio
if ( java.lang.Math.abs( oldHeight - newHeight ) >=
java.lang.Math.abs( oldWidth - newWidth ) ) {
oldHeight = newHeight;
inHeight = oldHeight - diffHeight;
inWidth = ( int ) ( ratio * ( ( float ) inHeight ) );
oldWidth = inWidth + diffWidth;
}
else {
oldWidth = newWidth;
inWidth = oldWidth - diffWidth;
inHeight = ( int ) ( ( ( float ) inWidth ) / ratio );
oldHeight = inHeight + diffHeight;
}
if ( fvmain.debug2 ) {
System.out.println( "ratio: " + ratio );
}
}
this.setSize( oldWidth, oldHeight );
}

Currently the layoutManager is set to BorderLayout. I'm using Borland
JBuilder X with JDK 4. The reason that I'm using BorderLayout is
because I have two components in this window, a bar which basically
contains a row of buttons (which act as sort of a graphical menu bar)
and a JPanel that acts as a drawing canvas.

Here's to hoping this is enough information. If you need more I'll be
happy to comply. Thank you.

.


Quantcast