• 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

Trying to get GridBayLayout to work

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this may get a better response in the Swing forum, moving.
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    Bartender
    Posts: 5167
    11
    Netbeans IDE Opera Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Greg, please BeForthrightWhenCrossPostingToOtherSites
    http://www.javaprogrammingforums.com/awt-java-swing/44193-trying-get-gridbaylayout-work.html
     
    I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic