wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Keeping JFrame the right size for components
 
Similar Threads
Will java survive...
Repaint Issue
Enforcing Minimum Size in Frames
fix JDialog position relative to its parent JFrame component
SWT on any other IDE?