How to get text advance (stringWidth) without a Graphics
instance in Java?
In the doc examples, stringWidth()
is taken from FontMetrics
, while FontMetrics
is taken from Graphics
.
Is it possible to obtain the same without a Graphics
?
In the notes below it is said, that Graphics
is required because it holds FontRenderContext
. But I have FontRenderContext
, just have no Graphics
.
So, suppose I have FontRenderContext
without a Graphics
. How do I get stringWidth()
then?