Calculate String Width
Is it possible to calculate the width of a String in a certain font without needing a Graphics object? I need to calculate this before a component is displayed in order to adjust the sizes of the components. getGraphics() is returning null at this point.
[261 byte] By [
coryb891a] at [2007-11-26 15:53:03]

# 3
I was actually looking at using this yesterday but I couldn't find any way to get a FontMetrics instance without going through the Graphics class (Graphics.getFontMetrics()). Similarly, I can't get a FontRenderContext without a Graphics instance.
# 5
Didn't my original post answer that question?
My control is being wrapped in a JScrollPane. I need to set the preferred size of the scroll pane based on the width of a String. If I try to do that during initialization before it is displayed, getGraphics() returns null so I get a NullPointerException.