File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Window fixed size problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Window fixed size problem" Watch "Window fixed size problem" New topic

Window fixed size problem

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
I have to make a screen of fixed size.
Means if the user drags the frame then also it should come back to its normal size.
I am able to make the frame of fixed size by doing

public void componentResized(ComponentEvent e) {
if( (this.getHeight() < this.DIALOG_HEIGHT) ||
(this.getWidth() < this.DIALOG_WIDTH) ||
(this.getHeight() > this.DIALOG_HEIGHT) ||
(this.getWidth() > this.DIALOG_WIDTH)
where DIALOG_WIDTH, DIALOG_HEIGHT are desired fixed sizes.
I am using gridbag layout to arrange the components in the Frame.
Whenever i drag the screen, due to the above code it is coming to the defined DIALOG_WIDTH, DIALOG_HEIGHT size, but the components are loosing their place.

Any solution for this ??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I am able to make the frame of fixed size by doing ...

did you try
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243

If you don't want your window to be resized, why not try calling setResizable(false) on your window when you are constructing it. That way you don't have to worry about resizing it to your desired size after a user has played around with it.

Cheers, Jared.

SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
MaheshNair Chandrasekaran

Joined: Jul 05, 2006
Posts: 1
I had a bug which needed the same solution and I had coded the same like

public void errorListDialog_ComponentResized(java.awt.event.ComponentEvent componentEvent) {

java.awt.Dimension dim=this.getSize();
if(dim.getWidth()<width || dim.getHeight()<height)

This works very much fine without the components get misplaced.Can you check whether you have used Gridbag layout for sure.
I agree. Here's the link:
subject: Window fixed size problem
It's not a secret anymore!