• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Using GridBagLayout

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I implement a JFrame and the layout for the JFrame as GridBagLayout. When I add a component to the JFrame and gridx=0 and gridy=0, it is being placed at the centre of the JFrame. Now I move the component to customize but I am unable to. Even on changing the gridx and gridy, I am unable to move the component.

I am also unable to pre-define the GridBagLayout grid by defining the columnwidths and rowheights for the GridBagLayout. This way I think by altering the gridx and gridy, I can move the component in the JFrame.

Any pointers as to what I am doing wrong?

Thanks & Regards,
Jayprakash
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to set weightx and/or weighty

from [somewhere]

"By default, weightx and weighty have the value 0. When all component's
weightx and weighty values are 0, no components get any extra space. In
addition, all components are positioned in the GridBagLayout relative to the
center of their container"

from the apidocs
weightx
"If all the weights are zero, all the extra space appears between the grids of
the cell and the left and right edges."
weighty
"If all the weights are zero, all the extra space appears between the grids
of the cell and the top and bottom edges."
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic