• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't get the desired position of label

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Link for tutorials
 
Mansoor Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Darryl. I'll try once again.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic