• 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

GridBagConstraints why o' why does this happen?

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is it with GridBagLayout(Consraints), is it me or does this simply not work!?

Can anyone explain the reason why I weould get totally different responses with the folowing longwinded way and my 'neater' way of setting the GBC params?

JButton btn1 = new JButton("A Button");

Long winded way:-


My way:-



Uses this simple Setter method


I have a few other components on the Panel all of which I have tried using the long winded way and my way, the long winded way gives me the layout I'd expect, my way and the components end up all over the place.
Surely the setGridBagConstraints() should simply be creating a new instance of GridBagConstraints and setting it's params?
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming the constraints are the same the result will be the same.

Just remember that using the "long winded" way any constraint you don't specifically reset is carried over from the last component. In your "neater" way you reset every constraint.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic