Submitted On 14-MAR-2000
RNaylor
The Frame.setResizable(false) is not an option for the task I have. The window needs to be able to be resized
down to a certain minimum size. I tried the other approach that was suggested, but this does not seem to work
either. The setSize() method is only called one time, and that is during the construction of the Frame object. I'm
open to any more suggestions.
Submitted On 23-MAR-2001
kuhse
See also bug ID 4170032.
Submitted On 26-APR-2002
MiguelM
This issue is also covered by RFE 4450706.
Submitted On 19-JUN-2002
rahul31
Even I'm facing the same problem. One workaround (not
hacky, not complex) is to check consistently for the frame
size in paint method. Something like...
public void paint(Graphics g)
{
double w = getSize().getWidth();
double h = getSize().getHeight();
if(w<600 && h<400) //Suppose Minimun size is 600x400
{ setSize(600,400);w=600;h=400; }
else if(w<600)
{ setSize(600,(int)h);w=600; }
else if(h<400)
{ setSize((int)w,400);h=400; }
// Do the painting here
}
My program seems to run just fine with this. If anyone
feels I'm technically wrong here please tell so.
Submitted On 19-JUN-2002
rahul31
OK HERES THE ABSOLUTE WORKAROUND....
public void paint(Graphics g)
{
double w = getSize().getWidth();
double h = getSize().getHeight();
if(w<600 && h<400)
{ setVisible(false); setSize(600,400); setVisible
(true); return;}
else if(w<600)
{ setVisible(false); setSize(600,(int)h); setVisible
(true); return;}
else if(h<400)
{ setVisible(false); setSize((int)w,400); setVisible
(true); return;}
mypanel.repaint(); // Components are on this panel
if(!firsttime) // Set to 'true' in frame constructor
{ mypanel.validate(); } // so that validate() isnt called
else // immediately on frame.show()
{ firsttime = false; }
}
This though looks a fragile implementation, provides more
than what most other codes can't, ie. an absolute clear
frame even after haphazard frame resizes.
Submitted On 06-AUG-2003
DBstein
Do not forget that the fix is desirable for all
java.awt.Window's, not just Frames.
Submitted On 01-SEP-2003
pilaftank
Here is a workaround that avoids hard-coding any dimensions:
-----
public static void lockInMinSize(final JFrame frame) {
//Ensures user cannot resize frame to be smaller than
frame is right now.
final int origX = frame.getSize().width;
final int origY = frame.getSize().height;
frame.addComponentListener(new
java.awt.event.ComponentAdapter() {
public void componentResized(ComponentEvent event) {
frame.setSize(
(frame.getWidth() < origX) ? origX :
frame.getWidth(),
(frame.getHeight() < origY) ? origY :
frame.getHeight());
frame.repaint();
}
});
}
-----
However, this type of "setMinimumSize()" feature should
definitely be built into Swing. Developing applications
faster (and with fewer lines of code) is essential for
Java's future market share.
Submitted On 05-NOV-2003
ragude2
None of the suggested methods disallow sizing the below its
minimum size. They all instead seem to draw the window below
its minimum size and then resize and redraw at minimum size.
This is highly unnatural. Is there a cleaner workaround?
Submitted On 30-APR-2004
lord_pixel
Still not working in the Tiger Beta 1 release on Windows NT.
Submitted On 25-AUG-2004
benjamin.podoll
This would be a good feature!
Submitted On 05-APR-2005
kwsanders
setMinimumSize() needs to be enforced on JFrame. The workarounds for resizing do not produce a very professional or desirable behavior.
Submitted On 29-JUL-2006
daveyost
Please also fix this bug for JFrame in 1.5.0.
Submitted On 17-NOV-2006
invictus2
I agree. This should be fixed. Both win32, .NET, GTK, and QT have the possibility of setting minimum and maximum window size, so why not also enforce getMinimumSize() on JFrame?
Submitted On 15-AUG-2007
I believe I really need this on the JFrame, not just the Frame
Submitted On 01-OCT-2007
I have just realized that this bug is really fixed. Here is the source code to prove it:
import javax.swing.*;
import java.awt.*;
public class ResizeTest extends JFrame
{
private final Dimension m_dim = new Dimension(200, 150);
public static void main(String args[]) {
new ResizeTest("Resize Test");
}
public ResizeTest(String title) {
super(title);
setLayout(new BorderLayout());
setSize(m_dim);
setMinimumSize(m_dim);
setVisible(true);
}
public Dimension getPreferredSize() { return m_dim; }
public Dimension getMinimumSize() { return m_dim; }
}
The problem was that the original example ommited call to setMinimumSize(m_dim);
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|