Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in layout a form.

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they're all set the same gridx/gridy, so they'd have to overlap
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is your understanding of gridx and gridy
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gridx: number of rows.
gridy: number of columns.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's gridWidth and gridHeight.

if you want things in a column,
gridx is the same for each, gridy changes
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
like i did:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want like this..
the last are combo boxes, i want in this fashion.
formimg.PNG
[Thumbnail for formimg.PNG]
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay i solved it....
here is what i did..


Thank you for your help...
 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic