File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Keeping JFrame the right size for components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Keeping JFrame the right size for components" Watch "Keeping JFrame the right size for components" New topic

Keeping JFrame the right size for components

Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I suspect there's a fairly simple solution to this that I'm not seeing so please forgive the silly question. Basically I simply want to keep my JFrame becoming too small to show all the components or becoming too large so that there's extra space. Seems simple but for some reason I'm not seeing the solution, any help is appreciated.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
If you are using layout managers java will do this for you. In the JFrame api scroll down to the section Methods inherited from class java.awt.Window to find the pack method. Follow it to the Method Detail section of the Window api to see what it does.

Another approach is the judicious use of JScrollPanes and layout managers that will fill the available space with your components. This seems to take some practice.

Helpful resources in the java tutorial might include Lesson: Laying Out Components Within a Container and Lesson: Learning Swing by Example.
I agree. Here's the link:
subject: Keeping JFrame the right size for components
It's not a secret anymore!