This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

GridBagLayout

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I am a little confused about GridBagLayout. I have the following
questions:
1) does the GridBagLayout honor preferred size? it seems so to me.
2) in the GridBagConstraints, say weightx = 4; does that mean the size
of component can go to 400% of its preferred size? or what does it
mean?
3) it seems to me that gridx, gridy, and gridwidth and gridheight are
all predominated by the preferred size of the components. and the ONLY
way to change the Size of the components is to use weightx and weighty
and fill in both directions. increasing gridwidth and gridheight
doesn't do anything to the acutal size of the component unless you
change your weightx and weighty and fill. am I correct?
4) also gridx and gridy are all relative to each other. is this true?
say you have 4 buttons a,b,c,d. you add them to (0,0),(1,1),(2,2) and
(7,7) and it will look like the button d is added at (3,3) instead of
having spaces in between the 3rd and 4th one.
5) also I don't know what the effect of doing
gridwidth=GridBagConstraints.REMAINDER or RELATIVE. it didn't seem to
make a difference in terms of size and location of the components. can
anyone give a simple example to illustrate these two constants'
effect?
thanks a bunch.
cw
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'll try to answer your queries one at a time...
1.) yes it does honor the size, but it's up to you to cancel that!
we know that when component size is less than size assigned to it , we place it through anchor. but when the size is greater we have the option to resize thru the fill option. the default is GridbagConstraints.None, but you can change it and resize the compontnt! got it?
2)weightx = 4 is just a value, a weight. compare it to the weighted average technique, or like having a clout. when there is extra space and all the weights are not 0(in that case all extra space appears at the edges) then the amount of space a row/column gets depends on the max weight it carries. meaning, if there are 2 rows and one has a component of weight 4 and the other of 2, then the first row gets more space. coz it has more weight. note that if the weight of the 2nd had been 0 it would have received no extra space and all the exta space would have gone to the first row. if it had a -ve weight, it would have actually lost some space!
3.)i think you're all warped up in the functions of various gbc fields and the above 2 should make things more clear
4) and 5) i'll try them first and then offer an answer.
hope the above explanations have helped
 
Chun Wang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anshuman. you're a big help.I will try testing it some more.
chun
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The following url gives the detailed explanation of gridbagconstraints and usage
http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbagConstraints.html
    Bookmark Topic Watch Topic
  • New Topic