• Post Reply Bookmark Topic Watch Topic
  • New Topic

GridBag layout  RSS feed

 
Ganesh Bhambure
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this tutorial
 
Campbell Ritchie
Sheriff
Posts: 55362
157
  • Mark post as helpful
  • send pies
  • 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.
     
    Jelle Klap
    Bartender
    Posts: 1952
    7
    Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hmm, GridBag.
    [ August 20, 2008: Message edited by: Jelle Klap ]
     
    Campbell Ritchie
    Sheriff
    Posts: 55362
    157
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Jelle Klap:
    Hmm, GridBag.


    Too late. Maneesh Godbole has beaten you to it.
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • 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
    • 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: 11445
    18
    Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
    • Mark post as helpful
    • send pies
    • 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
    Sheriff
    Posts: 55362
    157
    • Mark post as helpful
    • send pies
    • 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: 11445
    18
    Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Its ok.
    I think all of us are conditioned now to think GridBag==MadBeans !
     
    Campbell Ritchie
    Sheriff
    Posts: 55362
    157
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!