I'm trying to add a feature to my JavaFX application to save a PNG image. The solution I've seen almost everywhere to convert a JavaFX Image to a writable buffer consists in using SwingFXUtils.fromFXImage(...).
After a few hours of research, the SwingFXUtils class definitely comes from the javafx.embed.swing.SwingFXUtils
package, that should belong to the javafx.swing
module.
However, the javafx.embed.swing.SwingFXUtils
package is not recognised when I import it in a .java file in IntelliJ (unlike all my other JavaFX dependencies). I have tried adding requires javafx.swing;
to my module-info.java though IntelliJ does not recognise either : Module not found: javafx.swing | No documentation found.
I thought the library may need to be added to the project manually, though I cannot find it on the internet. I wouldn't know how to add it to the project either, if I found it.
I also suspected the package was changed in Java 18, though it seems it's still here according to its documentation : https://openjfx.io/javadoc/18/javafx.swing/javafx/embed/swing/SwingFXUtils.html
My module-info.java :
module fr.gbernard.pixelartref {
requires javafx.controls;
requires javafx.fxml;
requires javafx.swing; // Module not found: javafx.swing
requires org.kordamp.ikonli.javafx;
requires java.desktop;
opens fr.gbernard.pixelartref.view to javafx.fxml;
exports fr.gbernard.pixelartref;
}
All imports in the file I want to use SwingFXUtils in :
package fr.gbernard.pixelartref.utils.netpng;
import javafx.scene.image.Image;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.PixelReader;
import javafx.scene.image.WritablePixelFormat;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import javafx.embed.swing.SwingFXUtils;
import java.awt.image.BufferedImage;
Libraries :
Maven: org.apiguardian:apiguardian-api:1.1.22
Maven: org.junit.jupiter:junit-jupiter-api:5.8.12
Maven: org.junit.jupiter:junit-jupiter-engine:5.8.12
Maven: org.junit.platform:junit-platform-commons:1.8.12
Maven: org.junit.platform:junit-platform-engine:1.8.12
Maven: org.kordamp.ikonli:ikonli-core:12.2.02
Maven: org.kordamp.ikonli:ikonli-javafx:12.2.02
Maven: org.openjfx:javafx-base:18-ea+62
Maven: org.openjfx:javafx-base:win:18-ea+62
Maven: org.openjfx:javafx-controls:18-ea+62
Maven: org.openjfx:javafx-controls:win:18-ea+62
Maven: org.openjfx:javafx-fxml:win:18-ea+62
Maven: org.openjfx:javafx-graphics:18-ea+62
Maven: org.openjfx:javafx-graphics:win:18-ea+62
Maven: org.opentest4j:opentest4j:1.2.02
SDK : openjdk-18
IDE : IntelliJ
If you need any more information, please ask ^^