Open luiscastilho opened 2 years ago
The javafx.beans...
package is probably from the javafx-web
module.
Everything Processing needs is from the javafx-controls
module. It may be the case Processing / your machine doesn't have the javafx-web
module.
Hey, @micycle1. The javafx library seems to have all the JavaFX modules. In Windows they are located in Documents\Processing\libraries\javafx\library\windows-amd64\modules
. There I see javafx.base.jar
, javafx.controls.jar
, javafx.fxml.jar
, etc (7 items in total). But I don't know what I have to do to use this modules.
Of course I could create a library called javafxbase
and place javafxbase.jar
inside it. This way I would be able to import classes from this JAR. But I doubt that's the right way to fix this.
Hm, the problem is that JavaFX now uses modules, rather than the older classpath system. So we have to explicitly define which pieces of the library to include.
Unfortunately this isn't a great situation for Processing: we've only committed to JavaFX as a renderer—not doing generic JavaFX programming inside the PDE. All that other stuff isn't part of the Processing API, so we're not importing it. I guess we might be able to just tell it to import “everything.” That's overkill/messy/slow but might be the only way to support these cases. Just need to figure out the simplest/least messy way to handle this.
Thanks for looking into this, @benfry. And for all the awesome work in Processing of course! 👍
If it was possible to pass a command line parameter to Processing 4 so it would load the extra JavaFX modules, that would be enough for me and possibly for others in the same situation. Maybe a generic parameter to load code that was available in older versions of Processing and is not available anymore? Kinda messy but maybe better than to slow down Processing by always loading this code? In my case I would need this parameter/configuration to be passed along to exported applications as well, if possible.
Ok, digging into this a bit more… There are two issues:
First, just getting things to behave inside the PDE's preproc and error checker so that the imports work. (@sampottinger could use a hand here so that .jar files in the modules
subfolder of a library are included and parsed when doing package/class/method resolution)
And then second, making sure that's available for runtime. Initially I thought this was the bigger issue, but I think the the first problem is getting in the way a bit more at the moment, because as long as the JavaFX classes are being included, it should work during runtime.
Also, that being said, the OP code that was posted will not work:
import javafx.beans.property.SimpleIntegerProperty;
void setup() {
SimpleIntegerProperty version = new SimpleIntegerProperty(1);
}
void draw() {
background(0);
}
…because Import Library → JavaFX has not been used here. Just downloading the library doesn't make it magically work, you need to use Import Library first (or type out the import statement yourself, so that it picks up the library). But that's not the central issue here, because even when “Import Library” is used, this code still won't run.
Great! I believe once the JAR files in the modules
subfolder are included and parsed my problem will be solved.
And sure, I will import the JavaFX library. I posted the code above as an example that worked on Processing 3.x, but I realize the JavaFX code was moved to a library and that I will have to import it. No problem at all.
Thanks again
Added a new issue (https://github.com/processing/processing4/issues/522) in the main repo to cover the first part of what I mention above.
And in the meantime, this is still possible from other IDEs like IntelliJ or Eclipse, where you have to deal with all this stuff yourself; it's just that the PDE isn't set up to do this automatically.
The requisite jar files and libraries for javafx live in Documents/Processing/libraries/javafx/library/macos-x86_64/modules on my system, but they do have to be hooked up. See line 1086: https://github.com/processing/processing4/blob/3185ebae15f1ee894a9a2a056cc253b4677012e3/java/src/processing/mode/java/JavaBuild.java I am unable to use javafx controls and suspect it is because javafx.controls is not on the --add-modules list
Description
I have a project based on Processing 3 and I'm trying to make it work with Processing 4. It uses a few JavaFX classes and I just can't get them to work. I know JavaFX was moved to a separate library but even after installing it I get an error trying to import JavaFX classes in Processing 4.
BTW I asked this same question in discourse.processing.org but no one seems to know.
Expected Behavior
JavaFX imports should work once you install the JavaFX library.
Current Behavior
Installing the JavaFX library and trying to import a JavaFX class gives me this error:
The package “javafx” does not exist. You might be missing a library.
Steps to Reproduce
void setup() { SimpleIntegerProperty version = new SimpleIntegerProperty(1); }
void draw() { background(0); }