How to use JavaFX in Processing 4?

Possibly a dumb question but I can’t seem to figure it out on my own. Hopefully someone here can help me out.

Below is a simple code that works fine in Processing 3. Basically it just imports a JavaFX class. In Processing 4, JavaFX was moved to a separate library but even after installing this library I’m getting this error: The package “javafx” does not exist. You might be missing a library..

Anything I need to do besides installing the JavaFX library in Processing 4? It seems to have the JavaFX JAR files inside javafx/library/windows-amd64/modules but I still get the error above.

Thanks

import javafx.beans.property.SimpleIntegerProperty;

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

void draw() {
  background(0);
}

OS: Windows 10
Processing version: 4.0 beta 7

1 Like

Hello dear.
I have same issue with javafx library, have been able to resolve the issue?
if yes, how did you go about?

Hello,

There is a comment about this buried in here:

Install the library:

In your code:

import processing.javafx.*;

void setup() 
  {
  size(640, 480, FX2D);
  background(0);
  stroke(255);
  }


void draw() 
  { 
  //Your code...
  }
  

UPDATED 2022-06-30 References above updated.

:)

Do you have any suggestions on how to get this to run? I can get the window to work, but not the controls.

//https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Button.html

import processing.javafx.*;
import javafx.scene.*;
import javafx.scene.control.*;
//import javafx.scene.control.Control;
//import javafx.scene.control.Labeled;
//import javafx.scene.control.ButtonBase;
//import javafx.scene.control.Button;
//import processing.javafx.scene.*;
//import processing.javafx.controls.*;

void setup(){  
  size(640, 480, FX2D);
  background(209);
  stroke(255);
  Button button = new Button("Click Me");
}

void draw(){  
}
1 Like

I have only used the FX2D renderer in size() and can’t add more to this topic.

I did some testing and this works with Processing 3.5.4 but not with Processing 4.0b8:

// Add this for Processing 4:
//import processing.javafx.*;

// Code from example here:
// https://www.geeksforgeeks.org/javafx-button-with-examples/

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

void setup()
  {  
  size(640, 480, FX2D);
  background(209);
  stroke(255);
  
  Stage s = new Stage();
  
   s.setTitle("creating buttons");
  
  // create a button
  Button b = new Button("button");
  
  // create a stack pane
  StackPane r = new StackPane();
  
  // add button
  r.getChildren().add(b);
  
  // create a scene
  Scene sc = new Scene(r, 200, 200);
  
  // set the scene
  s.setScene(sc);
  
  s.show();
  }

void draw()
  {  
  }

:)

2 Likes

Very helpful; thank you.

1 Like

Hi all, sorry for the late reply. This thread became an issue in processing4-javafx repository: Error trying to import JavaFX classes in Processing 4 · Issue #15 · processing/processing4-javafx · GitHub

The proposed solution (not implemented yet) is for the JAR files in the modules subfolder of javafx library to become available to be imported and used in Processing code. That should make it possible to import any javafx classes.

1 Like

It should be a simple matter of adding these modules to the --addModules list. See line 1086 of the following file:
https://github.com/processing/processing4/blob/3185ebae15f1ee894a9a2a056cc253b4677012e3/java/src/processing/mode/java/JavaBuild.java

Addendum:

I just ran your code in Processing 4.1.2 on a Mac and it runs without error.