aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem in layout a form. 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 layout a form." Watch "problem in layout a form." New topic
Author

problem in layout a form.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
hello i have created a form layout using grid bag layout..
with four columns and few rows.
but i need to add three combo boxes in second column (for date month and year), but they are overlapping to each other.
here is my code..


i am giving the gridx=1 to all the combo boxes therefore the are overlapping to each other, but i want all in the same column.
how can i do??
i highlight the code for combo boxes..
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
gridbaglayout is so complex that we almost always need to see a working example of the problem i.e. compilable/runnable

so what's supposed to be at line 257?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
actually from line 257, i tried to format the code and tried to change the color, but unfortunately html formatting is not working inside code tags, i think.


this is the code for combo boxes.
all are coming in second column but overlapping each other.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
they're all set the same gridx/gridy, so they'd have to overlap
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
yes, and i make all the gridx of combo like:
gridx=1;
gridx=2;
gridx=3;
now my all the component are shift..
i want all three combos in the second column.
like in second column of all rows text fields are in front of label, but int this row i want three combos of date of birth, in place of text field only.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
what is your understanding of gridx and gridy
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
gridx: number of rows.
gridy: number of columns.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
that's gridWidth and gridHeight.

if you want things in a column,
gridx is the same for each, gridy changes
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
but if i change gridy, they all come in different different rows.
offcourse in same column(because i have not changed the gridx), but i change grid y so rows are changed.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
like i did:
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I honestly now have no idea what you're trying to do, or want.

from your 1st post
" but i need to add three combo boxes in second column (for date month and year), but they are overlapping to each other. "

then in your 3rd post
"i want all three combos in the second column. "

then in your 5th post
"but if i change gridy, they all come in different different rows. "

so, you want them in a column, original problem - they're overlapping,
now, if they all come in different rows - that's a problem?

perhaps it's time to fire up MS Paint and draw a picture of exactly whta you want and where it is to go,
because all of the above makes no sense to me i.e. in a column, not in different rows and not overlapping
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
i want like this..
the last are combo boxes, i want in this fashion.


[Thumbnail for formimg.PNG]

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
okay i solved it....
here is what i did..


Thank you for your help...
Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

I just want to help clarify something for you. In GridBagLayout there really isn't any upper limit on the number of columns and rows you have. The layout manager creates them on an as needed basis. What the gridx and gridy mean is not how many there are, but their relative position. So gridx = 0 means that you're putting something all the way to the left, gridy = 0 means you're starting at the top. Now if you increment y, you'll go down another row. If you increment x it'll take you over a column. The more you increment them, the more the layout manager allocates on the panel/frame/whatever. This is where your fill comes in, you can then fill components to take up all available space(GridBagConstraints.BOTH), fill only horizontal(GridBagContraints.HORIZONTAL), or fill only vertical(GridBagContraints.VERTICAL), none which means that it will compact the item as small as it can(GridBagContraints.NONE). You can also specify that an object takes up more than one space with gridheight and gridwidth.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in layout a form.