3

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.

  • Can't you open/export the module? See [here](https://stackoverflow.com/a/46483226/1803551). – user1803551 Dec 10 '17 at 02:45
  • I tried doing opens {com.sun.javafx.tk} in my module info, but it is saying the module can't be found. The error message is specifically "Caused by: java.lang.module.InvalidModuleDescriptorException: Package com.sun.javafx.tk not found in module" – Kayler Renslow Dec 10 '17 at 03:02

0 Answers0