Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2003

Tip: Looking for answers? Try searching our database.

How to prevent a window from resizing?

Thread view: 
Arnoud - 21 Aug 2003 23:42 GMT
Is there a way do disable the (default) resize option (right corner
with the mouse)of a Window??

Thanks in advance

Arnoud
Carl - 22 Aug 2003 13:32 GMT
I don't think it is good practice to take away a basic user control
like the ability to resize a window.  But you can do it by:

<yourJFrame>.setResizable(false);

> Is there a way do disable the (default) resize option (right corner
> with the mouse)of a Window??
>
> Thanks in advance
>
> Arnoud
Sandip Chitale - 22 Aug 2003 17:41 GMT
java.awt.Window is not resizable as there are no resize handles. You
can resize java.awt.Window objects programatically. So I assume you mean
java.awt.FRame when you say Window.

java.awt.Frame has a method:

public void setResizable(boolean resizable)

Sets whether this frame is resizable by the user.

In JDK1.4, you can use turn off the frame decorations with

   frame.setUndecorated(true);

This will make it look like a Window.

Prior to JDK1.4 you may have to listen to ComponentEvent and reset
the size every time in the componentResized(ComponentEvent ce) callback.
You could also override the setSize(Dimension) and setBounds(...) methods.

> Is there a way do disable the (default) resize option (right corner
> with the mouse)of a Window??
>
> Thanks in advance
>
> Arnoud
Sandip Chitale - 23 Aug 2003 02:49 GMT
Here is a more general example of min and max size:
/**
* FrameResize.java
*
* @author Sandip Chitale
*/
import java.awt.*;
import java.awt.event.*;

public class FrameResize extends Frame {

    public static void main(String args[])
    {
        Frame f = new FrameResize();
        f.setSize(300, 300);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
            });

        f.addComponentListener(
            new ComponentAdapter() {
                    public void componentResized(ComponentEvent ce)
                    {
                        Frame sf = (Frame) ce.getComponent();
                        sf.removeComponentListener(this);
                        sf.setSize(
                            Math.min(Math.max(sf.getSize().width, 200), 500) ,
Math.min(Math.max(sf.getSize().height, 200),500)
                            );
                        sf.addComponentListener(this);            
                    }
                }
            );
    }
 
}// FrameResize

> java.awt.Window is not resizable as there are no resize handles. You
> can resize java.awt.Window objects programatically. So I assume you mean
[quoted text clipped - 22 lines]
> >
> > Arnoud


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.