This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Layout Management : A nightmare  RSS feed

 
Mousa A. Rafi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having some real hard time with Layout Management. It seems like impossible to get the actual look I want.

Like I want to create a simple login form for my application that includes 2 labels, 1 textfield, 1 passwordfield and a button. I create a JPanel, set its layout as GridBagLayout(3, 2) and add the components to it. Then I add this panel to the JFrame (500, 400). Alas! all the components are distributed evenly throughout the frame, something that I don't want.

These kinds of things keep on happening. So, please help! Any tutorial, suggestions, tips, links, anything that will help me understand it is I need. Thanks.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layout management is a complex area and can seem bewildering in the beginning. The java tutorial has a lesson where you can start learning about it — Lesson: Laying Out Components Within a Container. It has lots of illustrations and examples.

Learning to make layouts seems to take some practice, patience, imagination and curiosity. The general recommendation is to start out by nesting panels with different layout managers to get the desired effect and then gradually learn about other possibilities, eventually finding your favorite approaches/solutions. The GridBagLayout technique shown below was given in the last tutorial version (replaced by the current, 11 Mar 2004 version). The tutorial is showing this kind of layout with SpringLayout now. The BoxLayout is more specialized. The api for the different layout managers contain pointers and hints that become illuminated with practice.

[ January 30, 2005: Message edited by: Craig Wood ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!