• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

GridBagConstraints Problem

 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add them into JPanel

 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I have not used GUI Builder, but Netbeans yes...
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic