Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to import JavaFX classes in Processing 4 #15

Open
luiscastilho opened this issue Mar 27, 2022 · 9 comments
Open

Error trying to import JavaFX classes in Processing 4 #15

luiscastilho opened this issue Mar 27, 2022 · 9 comments

Comments

@luiscastilho
Copy link

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

  1. Install JavaFX library in Processing 4.
  2. Restart Processing.
  3. Try to run this code:
import javafx.beans.property.SimpleIntegerProperty;

void setup() {
  SimpleIntegerProperty version = new SimpleIntegerProperty(1);
}

void draw() {
  background(0);
}

Your Environment

  • Processing version: Processing 4.0 beta 7
  • Operating System and OS version: Windows 10
  • Other information: JavaFX library v4.0 beta 5

Possible Causes / Solutions

If there's anything I need to do after installing the JavaFX library, please let me know.

@micycle1
Copy link

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.

@luiscastilho
Copy link
Author

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.

@benfry
Copy link
Contributor

benfry commented Apr 23, 2022

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.

@benfry benfry transferred this issue from benfry/processing4 Apr 23, 2022
@luiscastilho
Copy link
Author

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.

@benfry
Copy link
Contributor

benfry commented Jun 19, 2022

Ok, digging into this a bit more… There are two issues:

  1. 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)

  2. 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.

@luiscastilho
Copy link
Author

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

@benfry
Copy link
Contributor

benfry commented Jul 31, 2022

Added a new issue (processing/processing4#522) in the main repo to cover the first part of what I mention above.

@benfry
Copy link
Contributor

benfry commented Jul 31, 2022

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.

@vsquared
Copy link

vsquared commented Mar 15, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants