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!
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
Joined: Oct 16, 2002
make that setMaximumSize.
btw, if you want components (such as tables) to scroll, make sure to put them inside a JScrollPane. Bill
Joined: Oct 09, 2002
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com