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