Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagConstraints Problem

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add them into JPanel

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I have not used GUI Builder, but Netbeans yes...
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic