Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to disable the [ - ] resizing of a frame

 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have coded an application using frames and whenever, I resized the frame GUI changes and it looks weird. I just need to disable the re-sizing to solce this problem. Does anyone know how to do this in Swing? Thanks in advance.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a JFrame you can't disable that.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sadly, yes this is true, you can't constrain a JFrame's size like that.
The JFrame is a heavy-weight peer component; when you put up a JFrame, the VM is actually putting up an OS native window frame, but provides no API for you to restrict the window size, or change the look of the native window, etc.
You can, however, use JInternalFrames, of which you have complete control since they're lightweight, and restrict their size. Changing your JFrames to JInternalFrames is not that hard, since the JInternalFrames were written to "act" just like JFrames and have most of the same API methods.
Rob
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, what about setResizable( false )?
This disables resizing the frame by dragging on it's borders or clicking on its title bar, and it disables the maximize button on the frame.

The previous posts are correct if you are trying to disable the minimize button on the JFrame ( you can kinda disable this by making it listen for the event and then restore the frame ), but minimizing doesn't resize the frame anyway, so this shouldn't be a problem...

-Nate
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I generally do not think locking the size is a good idea. Unless it is a small dialog. You are making the assumption that all users use the same size monitor and have the resolution set the same. Learning the layout managers goes along way in making the GUI presentable with all resolutions and resizing. The next step that many take is to use the null layout. Do yourselves a favor and learn to use the layout managers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic