How to use JavaFX in Processing 4?

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