aspose file tools*
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 Spring in Action this week in the Spring 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.
 
wood burning stoves
 
subject: Keeping JFrame the right size for components