• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Window fixed size problem

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> I am able to make the frame of fixed size by doing ...

did you try
frame.setResizable(false);
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic