• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't get the desired position of label

 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, got a problem using GridBagLayout class. Going by the book, I tried to create a label which I want to be there at the start of the first line but sadly just couldn't get it right. I may be missing a thing or two.
Kindly help. Here's my code.



 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am getting is a label at the centre and on modification the label shifts to the first column but still in the middle. Its making me crazy by every hour.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have this

gbl.weightx=0.5;
//gbl.weighty=0.0;

why not try

gbl.weightx=0.5;
gbl.weighty=0.5;
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansoor, please UseCodeTags next time instead of giving it another colour.
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That helped Michael. Thanks man!
@Rob - How is it different from what I'm using?
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I always seem to be in a hurry. I got your point Rob. I'll be careful next time. Thank you!
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See how it a) maintains indentation, and b) adds syntax highlighting?
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for taking out time to answer my question and point out the flaws. Your help is greatly appreciated.
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
STILL HAVING PROBLEM:
I want to create a panel which has three labels and three textfields beneath them respectively. Something like this :

Due Date Class Batch Time

TextField1 TextField2 TextField3


But what I am getting is a lot of space between the first and the second desired row. Something like this :

Due Date Class Batch Time





TextField1 TextField2 TextField3





Here's my code. I wish to maintain the spaces between widgets as well. Please help.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is all left justified making it difficult to read. You may wish to fix this.

You are adding your GridBagLayout using panel to the contentPane BorderLayout.CENTER (by default) and so the panel is taking up the whole contentPane which is separating out your two rows. You may wish to add your panel tot he contentPane BorderLayout.NORTH or else find some other combination of nested JPanels each with its own layout manager to achieve the result you desire. For e.g.,

 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly what I seek help for. I could not get the widgets in the correct order. Refer me some tutorials, if possible, may be that could help.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Link for tutorials
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl. I'll try once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic