File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Window Size 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 Size" Watch "Window Size" New topic
Author

Window Size

Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
Can someone help me out? I am getting frustrated...
I would like to start a new Swing app, with a predefined width and height, centered in the screen. I would like this window to always stay the same size, regardless of the contents.
I have tried the following:

This seems to work for the first window, but subsequent frames/panels seem to be able to override this - i.e. when a large JTable is added the window grows to accomadate it. This is distracting to the user, and so I would rather have the JTable clipped, or scrolled.
Is there a way to make the window size static?
Thanks!
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
For each Frame (JFrame is a subclass of Frame) you instantiate, call setResizable(false) on it.
If you have subclassed JFrame, you can do this in the constructor.
There are other ways to control size (such as setMinimumSize, setPreferredSize, setManimumSize), but the above method may be easier.
Bill
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
setManimumSize

make that setMaximumSize.

btw, if you want components (such as tables) to scroll, make sure to put them inside a JScrollPane.
Bill
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
Thanks! This makes things better, but not perfect
However, some panels still change the widow size; it is as if all the settings I set are simply 'recommendations'. As a web developer, I am unaccustomed to not being able to set the window size once, and have it never change. If I add a long string (via JLabel), the window stretches instead of simply wrapping the text. Am I missing something, or must I start counting pixels everytime I want to add something to the screen if I want the window size to never change???
I am using these Swing components for the SCJD exam, so I should pass even if the window size changes. I simply find the flicker annoying.
Thanks!
--Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Window Size