This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes GridBagConstraints why o' why does this happen? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagConstraints why o Watch "GridBagConstraints why o New topic
Author

GridBagConstraints why o' why does this happen?

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
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?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagConstraints why o' why does this happen?
 
Similar Threads
GridBagLayout
Reuse of GridBagConstraints
GridBagLayout, & addComp() What are the parameters?
how to align components in GridBagLayout in JAVA swing
GridBagLayout