• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

GridBagLayout question

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I was trying my hands on using GridBagLayout to lay down my components.
Can anyone tell me... how to place a button and textfields with some constant width and height using this layout, so that even if the window is maximised, they stay to be of the same size.


i am trying to create this sort of structure
basically a form.
---------------------------------------------------
Label 1 TEXTFIELD
BUTTON
label 2 TEXTFIELD
---------------------------------------------------

Regards
Akhil
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi craig,

thanks for that code....can you tell me what i am doing wrong here....



structure which i am looking for to create with above code is this:--->



i want this structure to remain as it is...even when i maximize the window.I am simply not able to do this.i have drawn this image using Absolute Layout.........but i dont want to use Absolute anymore....how can i do the same thing using GridBagLayout....can you help me out with this.?

[ November 09, 2007: Message edited by: Akhil Jain ]
[ November 09, 2007: Message edited by: Akhil Jain ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your layout image shows the layout centered instead of alligned to the west/left. To
center this layout change all the anchor constraints form LINE_START to CENTER.
Use the insets constraints to alter the spacing among components.
Managing the weightx constraint is how we keep the components all aligned to the left. The
weightx values for all components should be zero except for the last component in each
row.

Edit:
Your layout image shows the layout centered instead of alligned to the west/left. To
center this layout change all the anchor constraints form LINE_START to CENTER.

And set all weightx constraints to zero.
[ November 09, 2007: Message edited by: Craig Wood ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic