Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keeping JFrame the right size for components

 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic