• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

align JLabel to left

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This is my favorite show. And this is my favorite tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic