Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

align JLabel to left

 
kalyan chowdary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I create a labels in JPanel,

JPanel is set to GridBagLayout,

but i want to put JLabel to left align,

i use
JLabel label=new JLabel("Item Name",JLabel.LEFT);

but its not working.

Help me,

Thanks in advance;
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All that the JLabel.LEFT in the constructor does is to tell the label to left-align it's contents. Depending on how the label is laid out in it's container this may or may not make a difference. (i.e. - if the label itself is only the size of the text, then it won't look any different. If the label itself is larger than the text, then the text will shift to the left.)

Check the size your label is in the layout of it's container - an easy way to see this is to set a border on your label.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic