I want to draw Strings containing subscripts on designated places in my JFrame. I know you can use html-coding to get subscripts on for example buttons and textfields, but I can't use those since the placement have to be dynamic.
The only option I've found is to check the string for numbers, then divide the string into substrings and draw each of these using different fonts. But I get a problem because it's very hard to calculate the length of a string in pixels.
Is there a simpler solution?
10-03-2005, 12:04 PM
Norm
Could you give an example of what your trying to do?
What is a String containing a subscript?
String s = "array[x]"; // A string followed by a [ followed by a string followed by ]
The FontMetrics class will give you pixel sizes of Strings.
10-04-2005, 08:19 PM
nspils
Why will YOU have to calculate the size of the string in pixels? Can't you use the Font class or the FontMetrics class to do all of this work for you?
Define a font which is your subscript font. When appropriate, display using that font, then switch back to the "base" font.