File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes problem in GridBagLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in GridBagLayout" Watch "problem in GridBagLayout" New topic
Author

problem in GridBagLayout

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
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

Joined: May 03, 2008
Posts: 4658
    
    5

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?


luck, db
There are no new questions, but there may be new answers.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
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

Joined: May 03, 2008
Posts: 4658
    
    5

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

Joined: Aug 20, 2011
Posts: 1001
    
    2
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

Joined: Oct 16, 2003
Posts: 1088
    
  10

This has been discussed earlier here


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Aug 20, 2011
Posts: 1001
    
    2
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

Joined: Oct 16, 2003
Posts: 1088
    
  10

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

Joined: Aug 20, 2011
Posts: 1001
    
    2
problem is solved....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in GridBagLayout