Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4320050
Votes 53
Synopsis Minimum size for java.awt.Frame is not being enforced.
Category java:classes_awt
Reported Against 1.3 , 1.2.2 , tiger
Release Fixed mustang(b51)
State 10-Fix Delivered, request for enhancement
Priority: 4-Low
Related Bugs 6318090 , 6318144 , 4441590 , 6396632 , 4900571 , 4450706 , 4913186
Submit Date 09-MAR-2000
Description


8 Mar 2000,   xxxxx@xxxxx   -- easily worked around.  Could not find any still-open
bugs re. this, so am filing new one.

java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)

Since there is no method to set a minimum size on a java.awt.Frame, the most
obvious way to control this behavior is to extend the Frame  customer  and override
the getMinimumSize() method. However, when this is done, the minimum size that
I set is not being enforced. Any other suggestions?

Sample code as follows:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

import java.awt.*;

public class ResizeTest extends Frame
{
   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);
      show();
   }

   public Dimension getPreferredSize() { return m_dim; }
   public Dimension getMinimumSize()   { return m_dim; }
}
(Review ID: 102158) 
======================================================================
Posted Date : 2005-08-16 11:23:48.0
Work Around




8 Mar 2000,   xxxxx@xxxxx   -- Frame.setResizable(false),
or override setSize() to check if requested (new) size is less than desired minimum
======================================================================
Evaluation
Need some new methods for minimum and maximum size of a frame.  Commit to Tiger.

  xxxxx@xxxxx   2000-03-17

Necessary javadoc changes:

(Preliminary Specification)
java.awt.Window:
 
    /**
     * Sets the minimum size of this window to a constant
     * value.  Subsequent calls to <code>getMinimumSize</code>
     * will always return this value. If current window's
     * size is less than specified by <code>minimumSize</code>
     * param it's automatically enlarged. If <code>setSize</code>
     * or <code>setBounds</code> call is made with width and height
     * less than specified by <code>setMinimumSize</code> window
     * will by automatically enlarged to minimumSize value.
     * Setting the minimum size to <code>null</code> restores
     * the default behavior.
     * <p>
     * Resizing operation may be restricted if user tries
     * to resize window below the <code>minimumSize</code> value.
     * This behaviour is platform-dependent.
     *
     * @param minimumSize the new minimum size of this window
     * @see Component#setMinimumSize
     * @see #getMinimumSize
     * @see #isMinimumSizeSet
     * @see #setSize(Dimension)
     */
    public void setMinimumSize(Dimension minimumSize)
 
    /**
     * {@inheritDoc}
     * <p>
     * Values of <code>d.width</code> or <code>d.height</code>
     * will be automatically enlarged if they are less than
     * window's minimum size specified by previous call to
     * <code>setMinimumSize</code>.
     *
     * @see #getSize
     * @see #setBounds
     * @see #setMinimumSize
     */
    public void setSize(Dimension d)
 
    /**
     * {@inheritDoc}
     * <p>
     * Values of <code>width</code> or <code>height</code>
     * will be automatically enlarged if they are less than
     * window's minimum size specified by previous call to
     * <code>setMinimumSize</code>.
     *
     * @see #getSize
     * @see #setBounds
     * @see #setMinimumSize
     */
    public void setSize(int width, int height)
 
    /**
     * {@inheritDoc}
     * <p>
     * Values of <code>width</code> or <code>height</code>
     * will be automatically enlarged if they are less than
     * window's minimum size specified by previous call to
     * <code>setMinimumSize</code>.
     *
     * @see #getBounds
     * @see #setLocation(int, int)
     * @see #setLocation(Point)
     * @see #setSize(int, int)
     * @see #setSize(Dimension)
     * @see #setMinimumSize
     * @see #setLocationByPlatform
     * @see #isLocationByPlatform
     * @since 1.5
     */
    public void setBounds(int x, int y, int width, int height)
 
    /**
     * {@inheritDoc}
     * <p>
     * Values of <code>r.width</code> or <code>r.height</code>
     * will be automatically enlarged if they are less than
     * window's minimum size specified by previous call to
     * <code>setMinimumSize</code>.
     *
     * @see #getBounds
     * @see #setLocation(int, int)
     * @see #setLocation(Point)
     * @see #setSize(int, int)
     * @see #setSize(Dimension)
     * @see #setMinimumSize
     * @see #setLocationByPlatform
     * @see #isLocationByPlatform
     * @since 1.5
     */
    public void setBounds(Rectangle r)
 
    /**
     * @deprecated As of JDK version 1.1,
     * replaced by <code>setBounds(int, int, int, int)</code>.
     */
    @Deprecated
    public void reshape(int x, int y, int width, int height)
  xxxxx@xxxxx   2005-06-10 13:18:36 GMT
Comments
  
  Include a link with my name & email   

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