# How to use JavaFX in Processing 4?

**URL:** <https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842>\
**Category:** Libraries\
**Created:** [March 19, 2022, 4:41pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842 "2022-03-19T16:41:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lui\_s](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@lui\_s](https://discourse.processing.org/u/lui_s)\
**Post date:** [March 19, 2022, 4:41pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/1 "2022-03-19T16:41:13Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![avong](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@avong](https://discourse.processing.org/u/avong)\
**Post date:** [June 30, 2022, 10:06am UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/2 "2022-06-30T10:06:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 30, 2022, 12:05pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/3 "2022-06-30T12:05:25Z")

</div>

Hello,

There is a comment about this buried in here:

- [GitHub - processing/processing4: Processing 4.x releases (currently in “beta”) that use Java 17](https://github.com/processing/processing4)
- [Processing 4 · processing/processing4 Wiki · GitHub](https://github.com/processing/processing4/wiki/Processing-4)
- [Move JavaFX to a separate library in the Contributions Manager · Issue #348 · processing/processing4 · GitHub](https://github.com/processing/processing4/issues/348)
- [GitHub - processing/processing4-javafx: JavaFX library for Processing 4](https://github.com/processing/processing4-javafx)
- [Issues · processing/processing4-javafx · GitHub](https://github.com/processing/processing4-javafx/issues)

Install the library:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/5/655a6f49a69b38902e997cb03ce7cef58dd70ed4.png)

In your code:

```auto
import processing.javafx.*;

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

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

```

UPDATED 2022-06-30 References above updated.

`:)`

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 30, 2022, 12:56pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/4 "2022-06-30T12:56:39Z")

</div>

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

```auto
//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(){  
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 30, 2022, 8:16pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/5 "2022-06-30T20:16:07Z")

</div>

> [@svan](#):
>
> Do you have any suggestions on how to get this to run?

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:

```auto
// 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()
  {  
  }

```

`:)`

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 30, 2022, 8:37pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/6 "2022-06-30T20:37:10Z")

</div>

Very helpful; thank you.

---

<div class="post-metadata">

**Author:** ![lui\_s](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@lui\_s](https://discourse.processing.org/u/lui_s)\
**Post date:** [July 1, 2022, 11:16pm UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/7 "2022-07-01T23:16:50Z")

</div>

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](https://github.com/processing/processing4-javafx/issues/15)

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.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [March 15, 2023, 8:53am UTC](https://discourse.processing.org/t/how-to-use-javafx-in-processing-4/35842/8 "2023-03-15T08:53:13Z")

</div>

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](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.
