wood burning stoves 2.0*
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
Author

Window fixed size problem

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
Hi,
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)
)
{
this.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
}
}
}
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
frame.setResizable(false);
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Hi,

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
Greenhorn

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.setSize(width,height);
}
return;
}

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: http://aspose.com/file-tools
 
subject: Window fixed size problem
 
Similar Threads
this animation code does not show o/p
how to get Maximum jar size supported on a handset?
method working, but not vice versa
swing paint performance
Unable to draw shapes beyond the margins of a JPanel