• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to get GridBayLayout to work

 
Greg Jackson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys I am trying to get the gridBagLayout function to sort my code to look like the attached image. I am having trouble
figuring out how to do it or even where to start. My code can be seen below and this was as far as I could get on my own.






circle.jpg
[Thumbnail for circle.jpg]
 
Knute Snortum
Sheriff
Posts: 3254
82
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this may get a better response in the Swing forum, moving.
 
Campbell Ritchie
Marshal
Posts: 52516
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Can you get your hands on a copy of Core Java II by Horstmann and Cornell. Find about Horstmann's GBC class, and read about that. There is a bit about GBC here. There are various tutorials about Grid Bag; try here in the Java® Tutorials.

Basically, you use the constraints object to specify things like xPos yPos (which columns and rows you start your Component off in) height and width (how many columns and rows it spans) etc. There are 11 fields which a constraints object has. If I remember correctly they are
xPos = column number starting 0 = far left
yPos = row number starting 0 = top
width
height
weightX and weightY: how much they change size in those directions as the
anchor: whether your Component is fixed to a particular corner of its space
fill: whether your Component fills the space available
insets (top, left, bottom and right): space to be left on those sides between the Component and the area it occupies (measured in pixels)
internal padding (X and Y) measured in pixels: a minimum size smaller than which your Component is not supposed to go.

There are alternatives:
  • Divide your space into smaller spaces by putting several JPanels on it. Each can have its own instance of layouts.
  • Find out about MigLayout. I have never used it bu people say it is very good.


  • We usually discuss such questions in a different location, so I shall move you thither. I see you have already been moved.
     
    Darryl Burke
    Bartender
    Posts: 5152
    11
    Java Netbeans IDE Opera
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Greg, please BeForthrightWhenCrossPostingToOtherSites
    http://www.javaprogrammingforums.com/awt-java-swing/44193-trying-get-gridbaylayout-work.html
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!