Processing and JavaFX

Hello,

There are many posts in the forum using JavaFX with Processing.

JavaFX code works with certain configurations but not with others.

These configurations may include:

  • Version of Processing
  • Operating system and version
  • Modification to the source code to add modules
  • Latest build of Processing has modifications (see above) added.
  • Adding JavaFX jar files to sketch
  • Adding import statements
  • JavaFX version if applicable
  • Anything I missed…

All the topics on this subject in this forum can complicate the journey for a new user and we need to stay on point and communicate clearly when discussing these.

I have managed to sort out all of these JavaFX issues for everything on Windows; not tested on a MacOS.
I rarely use JavaFX but have tried some of the examples and overcame any hurdles running these. I always enjoy a challenge!
A new user will certainly have challenges.

I suggest one clear concise communication on this in:

If I had the time I would contribute more but these days I simply do not.

A working configuration must include:

  • Operating system and version
  • Processing version
  • Additional requirements such as import statements, adding files
  • Any other relevant details

A working configuration for my setup:

  • Windows 10 Pro 22H2
  • Processing 4.3.2
  • Adding the 7x JavaFX jar files from the modules folder to the code folder in the sketch
  • Add this to sketch:
    import processing.javafx.*;

This GitHub issue discusses some recent changes to Processing for JavaFX:

Is it a problem or a question?

Please read:

:)

1 Like

Hello,

I posted this in the gallery recently but have moved it to here instead.

@svan The gallery post should include the working configuration to run the code.
Can you please add this?

It does not run on Windows 10 Pro 22H2 with Processing 4.3.2 as is:

It does run on Windows 10 Pro 22H2 with Processing 4.3.2 with some additions.

It works if I import JavaFX and drag and drop the 7 jar files (from the modules folder) onto the sketch window to add them (a folder called code is created and contains these):

I also added this to the sketch:
import processing.javafx.*;

Which will include this additional 1x required javafx.jar file:

You could include all the 8x jar files (from above) in the code folder as well and not need the import processing.javafx.*; statement.

Related:

It now works like it’s supposed to on Mac; so far I have only found one of my old files that won’t run, for reasons I don’t understand. This is without drag 'n dropping jar files. In the beginning I had to modify the editor source code to include all seven modules in order to use JavaFX which is why I made the pull request to add all of them. I also have Linux and Windows 11 systems that I rarely use and have discovered that I’m unable to run the JavaFX multiplication table demo after installing the most recent editor on each. In both cases the demo will run after drag 'n dropping the seven JavaFX module jar files onto the open sketch. That’s a problem that should be addressed. In my opinion we are missing out on using a good renderer and a nice set of JavaFX controls; graphics are a lot sharper with FX2D. For now a bug report seems to be indicated. I would like to see more input from other forum members on their experiences just to make sure they are seeing the same thing before filing the report.

The problem in Windows and Linux seems to be that the JavaFX module jars are in Processing/libraries/javafx/library/yourOS/modules where they are supposed to be, but the runtime does not know that they are there; apparently this issue has been around for some time and never been fixed. Until it gets resolved a work around could be to copy the .jar files from the library folder to a sketch folder named ‘code’ rather than hunting down the jar files and drag 'n dropping them onto an open sketch window. This code was found on StackOverflow and would need to be tested in the above environments to see if it really works. It successfully copied the .jar files on my Mac. You will need to substitute the name of your computer and your operating system. The JavaFX library would need to be installed in your editor to start with.

//https://stackoverflow.com/questions/71148185/how-to-copy-specific-files-from-one-directory-to-another-in-java
import java.util.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.File;
import java.nio.file.Files;
import java.util.stream.Collectors;
import java.nio.file.StandardCopyOption;
import java.util.stream.Stream;

try (Stream<Path> stream = Files.list(Paths.get("/Users/yourName/Documents/Processing/libraries/javafx/library/yourOS/modules"))) {
  List<Path> paths = stream.filter(path -> path.toString().endsWith(".jar")).collect(Collectors.toList());
  for (Path source : paths) {
    Path destination = Paths.get("/Users/yourName/Documents/Processing/yourSketch/code" + File.separator + source.getFileName());
    Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
  }
}
catch (IOException e) {
  println(e);
}

Hello folks!

I can run JavaFX code examples (links below) with:

  • Windows 10 Pro 22H2
  • Processing 4.3.2

Steps:

  • Install the JavaFX library.

  • Import the JavaFX library in your code:

  • Add the JavaFX modules (jar files in modules folder) to your sketch folder.
    I have some code below to assist with finding them.
    The simplest way to do this is to drag and drop them into your sketch window.
    This will create a folder called code that contains them.
    Or…
    You cold also manually create a folder called code and copy the JavaFX modules into this.

  • I suggest you create a code template that contains these JavaFX modules for future use!
    You then “Save as” a new sketch to use in future.

I am able to run these examples from the forum with steps provided in this post for W10 and Processing 4.3.2:

Code to assist with finding the JavaFX modules folder:

// Assist with finding JavaFX modules and open folder
// Opens the folder on a Windows 10 system
// Author: glv
// Date:   2025-02-04

// Insight gleaned from various sources; seek and you shall find.

// Note:
// It only works with a new sketch name starting with "sketch" !
// You MUST save the sketch folder first !
// If you don't save it it points the %temp% directory.

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

void setup()
  {
  String sp = sketchPath("");  
  println(sp);
  
  String path = sp.substring(0, sp.indexOf("\\sketch"));
  println(path);
  path = path + "\\libraries\\javafx\\library\\windows-amd64\\modules";
  
  println();
  println("This is where the JavaFX modules are:");
  println(path);

  // Specify the path of the folder you want to open
  File folder = new File(path);

  if (folder.exists() && folder.isDirectory()) 
    {
    try 
      {
      Desktop.getDesktop().open(folder);
      } 
    catch (IOException e) 
      {
      e.printStackTrace();
      }
    } 
  else 
    {
    System.out.println("The specified folder does not exist or is not a directory.");
    }
  }

Output:

Opens this folder on my system:

I encourage you to explore the references below to help understand and navigate this.
There are some menu items in the Processing PDE to explore that are very useful!

Additional references:

And there is main Processing website!

Have fun!

:)

Hello again!

If anyone can contribute to this request below please respond to the GitHub topic or submit a report:

Add all seven of the javafx modules to JavaBuild.java by vsquared · Pull Request #856 · processing/processing4 · GitHub

And hello @stefterv I see you are here as well!

:)

2 Likes