This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes GridBagConstraints Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagConstraints Problem" Watch "GridBagConstraints Problem" New topic
Author

GridBagConstraints Problem

Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Hi!

Please run the code below. I would like that the second text field in the second row to be right after the first text field (in the second row).
I would also like to have the components in the top-left corner.

Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
You can add them into JPanel

Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
good idea.

yeah, I can use one JPanel per row, but I would like to know what's wrong with the constraints. And I still need to position the elements in the top-left corner.

Thank you!
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112

or you can try

for the component that contains GBL1Panel, but these often fails to function correctly



GridBagConstraints.anchor is used only for the components inside your GBL1Panel


Edit: and in GridBagLayout column widths are defined as what is the widthest component in column (component.getPreferredSize().width). you can use GridBagConstraints.gridwidth if some component should cover one or more columns
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
The first worked, but the second didn't.

Thanks very much for your help.

I almost don't do swing stuff, but I have to change one app from web to desktop. argh

After these problems with GridBagConstraints I started to use NetBeans' GUI builder.
Do you use some GUI builder or do you do your GUI coding?
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
Sorry while I looked your code a little better just fix one line and add another in your orginal code

FIX

ADD


And the anchor thing you get from

like I said in last post
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
No I have not used GUI Builder, but Netbeans yes...
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Mikko Kohtamäki wrote:Sorry while I looked your code a little better just fix one line and add another in your orginal code

I hate when pass a lot of time thinking in a problem and it was a simple mistake.
I just forgot to pass the constraint...

Thanks a lot! I'll give GridBagLayout one more chance. xD

Mikko Kohtamäki wrote:No I have not used GUI Builder, but Netbeans yes...

I'm not sure if you understand. Just to clarify, GUI builder is a tool that NetBeans has to create graphical user interfaces. :]
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
I'm not sure if you understand. Just to clarify, GUI builder is a tool that NetBeans has to create graphical user interfaces. :]


Yes I understanded I just enjoy more coding by hand, builders gives me a headache... in netbeans I think it uses GroupLayout only...
 
GeeCON Prague 2014
 
subject: GridBagConstraints Problem