• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in GridBagLayout

 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i m designing a registration form in swing, initial i added two textfields and labels to my frame, but the only one textbox is visible to me and when i maximize the screen, label is also visible to me but inside the text box, but second label and text boxes are not visible to me..
i m using GridBagLayout.
here is my code:
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't run your code, but I suspect the problem is due to some of the components being added with a gridwidth/height = 0. What exactly did you hope to achieve by that?
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i want my first label in first line first column, first textbox in first line second column.
then second label in second line first column and second text box in second line second column...likewise..just like a registration form.
that's y i did like this:


also i want when i maximize my form my text box should fill horizontally, but gbConstraints.fill is not working for me.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:that's y i did like this:

Please UseRealWords <- link

Do you understand what gridwidth and gridheight signify? Read the API.
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...
i got it, it's working now..
GridWidth is the number of columns the component occupies..
GridHeight is the number of rows the component occupies..



but still both the text fields and the labels are in the center of my form, they are not starting from the top??
is it happening due to the default layout of the frame, isn't it??
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been discussed earlier here
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, as GridBagConstraints has default alignment to be center, i have change my code and also set weightx and weighty to 0.
but it still showing in the center to me...
here is updated code:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> i have change my code and also set weightx and weighty to 0. 

you cannot program using a white cane.
read the apidocs!
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
weightx is:
The grid bag layout manager calculates the weight of a column to be the maximum weightx of all the components in a column.

But how it is relate to my problem, the default layout is center, and i changed it to north in my code.

???
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have pasted only a part of the API docs for weightx - which indicates that you have read only a part of that. You have to read it in full and then try. Read on the part where 'all weightx is 0'. I guess you don't want me to paste the apidoc all over here...
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem is solved....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic