Font metrics in JavaFX Canvas

David Gilbert dave at
Thu Nov 30 07:26:31 UTC 2017


I have an open source project FXGraphics2D [1] that provides a Graphics2D API for the JavaFX canvas.  It is open source and used to provide JavaFX support for JFreeChart [2] and Orson Charts [3].  It can also be used more generally for any code that targets the Java2D API.

One limitation that I’ve encountered is that there is no API to get font metrics for fonts rendered on the JavaFX canvas, so it is difficult to implement the method Graphics2D.getFontMetrics(Font f) accurately.  As a result, text alignment is difficult, for example see the tick labels on the vertical axis in this chart:

There is a feature request in the bug tracker, open for some time, that targets this particular feature.  I’d like to highlight it for (hopefully) some attention in a future JDK release: <>	

Best regards,

David Gilbert

[1] <>	
[2] <>
[3] <>

More information about the openjfx-dev mailing list