I just started using JavaFX 11, and SwingFXUtils seems to be gone (or renamed?)
I tried to download it manually, but the module-system complained about import sun.awt.image.IntegerComponentRaster;
, and I couldn't get it to work.
I need to convert Swing Icon to JavaFX image.
Since Java 9, SwingFXUtils
has been moved to the javafx.swing
module, under the package javafx.embed.swing
.
See JavaFX 9 Javadoc and the new JavaFX 11 Javadoc, hosted at https://openjfx.io.
If you have any issue with your sample, make sure you are adding the proper VM options. See the samples from the getting started guide.
Probably you will need to add something like:
--module-path <path-to>/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.swing
SwingFXUtils is still there if you have correctly added the javafx.swing module to your build path (see answer from José) but importing an internal class like sun.awt.image.IntegerComponentRaster
is not allowed anymore.
To convert your icon you can try this:
Icon icon; // Your icon
BufferedImage image = (BufferedImage)((ImageIcon)icon).getImage();
WritableImage writable = SwingFXUtils.toFXImage(image, null);
Whether this works or not depends on how your icon was created but it is worth a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With