# JavaFX Unable to add modules to Processing IDE

**URL:** <https://discourse.processing.org/t/javafx-unable-to-add-modules-to-processing-ide/41272>\
**Category:** Coding Questions\
**Created:** [March 14, 2023, 2:59am UTC](https://discourse.processing.org/t/javafx-unable-to-add-modules-to-processing-ide/41272 "2023-03-14T02:59:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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 16, 2023, 6:43pm UTC](https://discourse.processing.org/t/javafx-unable-to-add-modules-to-processing-ide/41272/5 "2023-03-16T18:43:16Z")

</div>

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.

1. Open the “java” folder.
2. Open the “src/processing/mode/java” folder.
3. Open the file “JavaBuild.java”
4. 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:**

```auto
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:**  
 ![javafx_btn](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/7/3711610ab0ee500986b8ba69a1bdb95949e2455c.png)

Special thanks to @glv for valuable assistance.

---

_[View the full topic](https://discourse.processing.org/t/javafx-unable-to-add-modules-to-processing-ide/41272)._
