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 Can't get the desired position of label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't get the desired position of label

Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
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.




kingmansoor
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
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

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

Joined: Oct 27, 2005
Posts: 19541
    
  16

Mansoor, please UseCodeTags next time instead of giving it another colour.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
That helped Michael. Thanks man!
@Rob - How is it different from what I'm using?
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

See how it a) maintains indentation, and b) adds syntax highlighting?
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
Thank you for taking out time to answer my question and point out the flaws. Your help is greatly appreciated.
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 14, 2008
Posts: 17
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

Joined: May 03, 2008
Posts: 4522
    
    5

Link for tutorials


luck, db
There are no new questions, but there may be new answers.
Mansoor Khan
Greenhorn

Joined: Apr 14, 2008
Posts: 17
Thanks Darryl. I'll try once again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get the desired position of label
 
Similar Threads
Problem with GridBagLayout Manager while adding any component
GridbagLayout
GridBagLayout resize issue
Problem displaying JTable inside a JScrollPane
GridBagLayout issues