This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Window fixed size problem

 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I am able to make the frame of fixed size by doing ...

did you try
frame.setResizable(false);
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
MaheshNair Chandrasekaran
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic