| Author |
GridBagConstraints Problem
|
Leandro Coutinho
Ranch Hand
Joined: Mar 04, 2009
Posts: 415
|
|
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: 415
|
|
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: 415
|
|
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: 415
|
|
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...
|
 |
 |
|
|
subject: GridBagConstraints Problem
|
|
|