• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting text for AWT List component - Tricky!

 
krishna joginpalli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
So does this mean I am doing the best that can be done? No suggestions??
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!