• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Choosing a Layout Method...

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone!
I am trying to build an application, but I'm getting hung up on the layout manager to use to get the program 'looking right.' Here's what it should have:
The window is 700px by 600px. I want a panel to occupy, starting at 0, 0 coords, 400px by 600px. Then, starting at 405, 0 coords, an area 295px by 300px. The last section, will start at 405, 305 coords, and be 295px by 295px. Here's a crappy ascii drawing of what it should look like.
___________________
|*********|******|
|*********|******|
|*********|******|
|*********|_______|
|*********|******|
|*********|******|
|*********|******|
|__________|_______|
Ingore the asterisks. They're there only for spacing purposes. )
I've tried using GridBagLayout and GridBagConstraints, but for some reason, it just plops all of the components right in the center, in an area about 25px by 25px.
Could someone give me some advice and lead me in the right direction? It is GREATLY appreciated, as I've tried all I know to do. As you can probably tell, I'm still new to JFC/Swing/AWT. Thanks again! )
[ January 04, 2003: Message edited by: Martin Clifford ]
[ January 04, 2003: Message edited by: Martin Clifford ]
[ January 04, 2003: Message edited by: Martin Clifford ]
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
If you really want to use absolute sizes for the components of your GUI screen, then you shouldn't use a "LayoutManager" at all. I think a better solution would be to determine the sizes of your GUI components (buttons, labels, text-fields, etc -- not the panels and other containers) and then use a "LayoutManager" (like "GridBagLayout") that tries to layout those components using their preferred size.
Have you not looked through the vast amount of information on this subject that is available on the Internet? If you need some recommendations, please let me know.
Hope this has helped you.
Good Luck,
Avi.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avi is right... you don't need to think about the absolute pixel sizes of your components when you are using a layout manager. You just need to think about their relative sizes ( i.e. the percentage of the frame they will take up. ) Especially with grid bag layout... Have a look at this code. It shows how to use GridBagLayout to get the layout you wanted. Especially look at the weightx and weighty values, they are the percentages of the row or column for the component to take up.

 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for your replies! The example code led me to a MUCH MUCH better understanding of how GridBagLayout works! God I love this forum! )
Thanks again!
Your very much indebted protege` (hehe),
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic