• 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

GridBag layout

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I want to design frame containing buttons. labels, combo etc.
I have screen picture requirement. According to that am try place different components on panel using GridBagLayout.
But I am not getting required layout structure.If I try to adjust constraints of one component other get disturb.
Is there ant tricks to set constraints for Grid bag Layout?
Does any body guide me how to use grid bag layout so I can get my required resultant screen?
Any pointer appreciated .


Thanks
- Ganesh
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out this tutorial
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maneesh Godbole:
Check out this tutorial

Maneesh, did you really send him that with no further explanation??

There is a class called GBC which Cai Horstmann developed (look here and search for GridBag on the page). That allows you to set all your constraints in a single statement. If you grasp the concept of GBC, it is easy enough to write your own version. Just don't do what I did once, passing null as the insets value.
The GridBagLayout API page has a list of what the constraints are.

Some Components (eg JTextField) shrink down almost to nothing unless you instruct them not to. Try:
  • setting a preferred size on the Component
  • setting a HORIZONTAL or BOTH value for the fill.

  • Apart from that, start small and practise with larger applications.
     
    Bartender
    Posts: 1952
    7
    Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmm, GridBag.
    [ August 20, 2008: Message edited by: Jelle Klap ]
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Jelle Klap:
    Hmm, GridBag.



    Too late. Maneesh Godbole has beaten you to it.
     
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, that link is relevant because it is true. Unless you have to learn GridBag, don't!
     
    Jelle Klap
    Bartender
    Posts: 1952
    7
    Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Campbell Ritchie:


    Too late. Maneesh Godbole has beaten you to it.




    Haha, serves me right for not making the effort to follow every link from here to the end of the Internet
     
    Maneesh Godbole
    Bartender
    Posts: 11497
    19
    Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Campbell Ritchie:
    Maneesh, did you really send him that with no further explanation??

    There is a class called GBC which Cai Horstmann developed (look here and search for GridBag on the page).



    Well the link does point to the "Taming the GridBagLayout" article page by Cay Horstmann, and at the end of the page, one can download the GBC.java class, the same as you mentioned...and the madbean link is quiet funny!
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am very sorry, Maneesh; I have read your link wrongly. I thought you had sent the madbeans link which Jelle Klap quoted later (and it is well worth opening over a cup of coffee!), whereas in fact you quoted the Cai Horstmann link I was trying to direct people too.

    I have got it all wrong Sorry again.
     
    Maneesh Godbole
    Bartender
    Posts: 11497
    19
    Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Its ok.
    I think all of us are conditioned now to think GridBag==MadBeans !
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Maneesh Godbole:
    Its ok.
    I think all of us are conditioned now to think GridBag==MadBeans !

    I have been conditioned like that for ages.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic