• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Best Layout For 2 JLabels  RSS feed

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone advise me on the best Layout for 2 JLabels inside a JPanel. The Labels should always be side by side, instead of one on top of the other, and stuck at opposite ends of the JPanel, but in the case of the one on the right, it should not shift when text in it is changed. Thanks so much for your help.
 
Saloon Keeper
Posts: 9137
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Isaac,

From the top of my mind, BoxLayout would be good for this. You can add a label, then add some glue, and add your second label. The glue will take up the extra space. Take a look at Box.createHorizontalGlue().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!