I greatly appreciate your interest and help with this (and other problems in the forum).
What to modify:
Start with the link that you provided above.
- Open the “java” folder.
- Open the “src/processing/mode/java” folder.
- Open the file “JavaBuild.java”
- Go to line 1086
change:
“–add-modules”, “javafx.base,javafx.graphics,javafx.swing”,
to:
“–add-modules”, “javafx.base,javafx.graphics,javafx.swing,javafx.controls”,
This should allow us to use javafx.controls in our Processing javafx projects. The way it is now we are unable to do this in Processing 4 as you are aware. Interesingly we can use SwingNode to add Swing controls (because they did add the javafx.swing module) but these controls are really ugly with a rectangular halo when initially used. This can be worked around by using a system call to set a transparent background and then jostling the frame to cause a refresh, but this is simply making it more difficult than it has to be and would be solved by using javafx controls to start with.
Why I think it will work:
If you try to compile/run pure javafx files from the command line you have to use “javac” and “java” with the “–add-modules” option added to both. If the correct modules are not added the code fails. For example:
To compile:
javac --module-path javafx-sdk-18.0.2/lib/ --add-modules javafx.controls,javafx.graphics,javafx.media,javafx.fxml ClickMe.java
and to run:
java --module-path javafx-sdk-18.0.2/lib/ --add-modules javafx.controls,javafx.graphics,javafx.media ClickMe
I believe that line 1086 determines what is inserted for the --add-modules option when our code is compiled and ran in Processing 4.
It does work!!
I followed the build instructions referenced in the link above (hardest part was getting apache-ant installed on Mac); after making the modifications to line 1086 of JavaBuild.java file outlined above the following code ran without error. Beautiful javafx button output is shown below that. I hope that the same modification will be made to Processing4 so that others can use these controls. Since Processing doesn’t have its own widgets I think it would be a nice addition for those that use controls in their projects.
Source code:
import processing.javafx.*; // Add this for Processing 4:
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
void setup() {
size(1, 1, FX2D);
Stage stage = new Stage();
stage.setTitle("Button demo");
Button btn = new Button("button");
btn.setLayoutX(80);
btn.setLayoutY(80);
Pane pane = new Pane();
pane.getChildren().add(btn);
Scene scene = new Scene(pane, 250, 200);
stage.setScene(scene);
stage.show();
}
void draw() {
}
Output:
Special thanks to @glv for valuable assistance.