• 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

Swing

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to use the 'Grid Bag Layout'? Can anyone give me some sample program on that?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> How to use the 'Grid Bag Layout'?

lots of experimentation, trial and error, late nights, coffee, whisky, v_alium.

start with sun's tutorial
http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

there are better ones via google, but I've yet to come across one that explains it easily.

[edit] v_alium is censored??, learn something every day
[ September 20, 2006: Message edited by: Michael Dunn ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be sure to watch this training video.
 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a very great tool that will make you understand the GridBagLayout thoroughly

This is a free tool and i have uploaded it to rapidshare
Hope it works fine

http://rapidshare.de/files/33844333/gridbag.zip
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This comes up regularly on these fora.
The hard part to understand about GridBag is not the layout, but the constraints. The constraints are:
  • gridX which means column, starting with 0=left, and
  • gridY which means row, 0=top,
  • gridwidth, how many columns covered
  • gridheight, how many rows etc.
  • weightx, how much it expands left-to-right,
  • weighty ditto up and down
  • anchor, which if any side or corner of its space the component clings to
  • fill, whether it fills its space horizontally, vertically, or both ways
  • Insets, an object representing the spacing from the edge of its area
  • ipadx, internal padding between the spaces left-to-right (I think) and last but not least,
  • ipady, ditto up and down.
  • Now if you use GridBagConstraints, you have to write myConstraints.gridx = 123;
    myConstraints.gridy = 234; every time you add a Component. So your consstraints takes up as much space as the rest of the coding. Find a copy of Horstmann & Cornell's book
    C Horstmann, G Cornell, Core Java 2, 7/e, Vol I-Fundamentals, Santa Clara CA: Sun Microsystems Press (Prentice-Hall) (2004), pages 430ff. Find the class they call GBC.
    You can now add things like this:-
    You can download a copy of the GBC class from Horstmann and Cornell here.
    And I like the tool which Khaled Mahmoud quoted.
    reply
      Bookmark Topic Watch Topic
    • New Topic