• 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

Formatting text for AWT List component - Tricky!

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am using JDK 1.1.8 for an Applet development. To preserve the look and feel, I need to use variable width fonts with the AWT List components. I can't use fixed width fonts.
A List cannot have multiple columns, so I am concatenating the two Strings (with spaces between them for an offset). The problem is that I can't get the second String perfectly aligned. I am using the FontMetrics class to calculate the width of the first String and pad enough spaces to get the right offset. But because the width of the alphabet is not in multiples of the width of the space character, the alignment of the second String is slightly off.
Is there any special/control character that I can use in place of the space? Or is there any other approach to this problem?
Thanks in advance,
Krishna
 
krishna joginpalli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So does this mean I am doing the best that can be done? No suggestions??
 
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
Krishna,

There is a character for tab ( \t )... this may work to align your data, but it may put too much space in...

Otherwise you can't do much with just a regular AWT List... I'm sure the Swing alternative could do this, or you could make a custom component to mimic a List but have this behavior, but it would probably be way too much trouble...

HTH,
-Nate
 
reply
    Bookmark Topic Watch Topic
  • New Topic