• Post Reply Bookmark Topic Watch Topic
  • New Topic

Components are centered while using GridBagLayout

 
Arijit Deb
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm adding some components in a panel which has GridBagLayout as layout. I've started adding the components from the beginning of the panel (using gridx=0,gridy=0).
Now from another file I'm calling a method which is returning this panel. And this panel is added to my programs main Panel (which has any layout, say GridLayout). So while I'm displaying my main panel why the components that were added shown centered, why not from the beginning?
Can anyone help me regarding that, how to show the components as they were added?
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
What fill are you using in your constraints? And what anchor?

Have you come across the GBC class of Cai Horstmann's? Please read about that, and see if that won't make your GridBag programming easier.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> why the components that were added shown centered

generally indicates not setting gridBagConstraint's weightx/weighty
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!