In JavaFX 8 and Java JDK 8, I used the com.sun.javafx.tk.FontMetrics
class to compute text width. However, with the release of Java 9 and Project Jigsaw, the package is no longer visible.
Here is an example of the former methods I used:
FontLoader fl = Toolkit.getToolkit().getFontLoader();
FontMetrics fontMetrics = fl.getFontMetrics(font);
int textWidth = (int) fontMetrics.computeStringWidth(text);
int textHeight = (int) fontMetrics.getLineHeight();
What I need is a way to compute a String's width by providing a JavaFX Font (javafx.scene.text.Font
). I would prefer not using AWT components to measure text width.