2

I am using Netbeans IDE 17. I have a problem with setting a different JavaFX platform version. Therefore I cannot create new JavaFx project.

Tools/Java Platforms:

Add Platform

When creating a new JavaFX project I tried multiple times to add new platforms, but I cannot choose them in the combobox:

New Project

skomisa
  • 16,436
  • 7
  • 61
  • 102
Enyko
  • 23
  • 3
  • 2
    I think the new JavaFX platform stuff in NetBeans is obsolete and broken. Instead follow the getting started instructions for NetBeans at openjfx.io. – jewelsea Apr 07 '23 at 19:45
  • 2
    If you have been stuck for a long time, try a different approach. To quickly get started, I advise downloading idea and using the [new JavaFX project wizard](https://stackoverflow.com/questions/74764217/error-javafx-runtime-components-are-missing-with-intellij-idea-maven-and-jdk/74764297#74764297). – jewelsea Apr 07 '23 at 19:46
  • 3
    you can make a maven javafx project in netbeans [like so](https://stackoverflow.com/a/74924150/7587451) – Giovanni Contreras Apr 07 '23 at 19:59
  • 3
    [_"Don't try to create a JavaFX project."_](https://stackoverflow.com/a/73611827/230513) – trashgod Apr 07 '23 at 21:17
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 08 '23 at 05:24

1 Answers1

4

The good news is that your issue is fairly easy to fix. The bad news is that you are going to encounter another problem once that is resolved, for which there is no easy fix.

First, note from your screen shot that you are invited to provide a "JavaFX Platform" rather than just a "Java Platform". That is, you need to provide a JDK which includes the JavaFX modules, and presumably your selection of JDK 20 (Default) is not valid.

Azul Systems and BellSoft are two JDK vendors offering editions that bundle the necessary JavaFX (OpenJFX) libraries. Here is a screen shot of the Azul site, https://www.azul.com/downloads/?package=jdk#zulu

Azul Download

Be sure to specify JDK FX for the Java Package. I downloaded the zip (rather than the msi) and after unzipping had a top level directory named zulu19.32.15-ca-fx-jdk19.0.2-win_x64. Use Tools > Java Platforms > Add Platform... to create a new Java platform, specifying that directory. I named my new platform Java193215Azul:

Add Platform

Now you should be able to avoid the problem shown in your screen shot. Navigate to File > New Project... > Java with Ant > JavaFX > JavaFX Application, and click Next >. On the New JavaFX Application screen in the JavaFX Platform field select the Azul SDK you just downloaded and added as a Java platform:

NetBeans Wizard

There should be no error now, and you can click Finish to generate your project.

That resolves your issue, but it's important to note that when you build the JavaFX application generated by the NetBeans wizard you will get an unrelated build error:

Build error

A bug report for that issue was raised almost a year ago, but has not been resolved. See the NetBeans Bug Build Failed #3996:

When I build javafx app this error appear "Unable to create javax script engine for JavaScript in javafx".

To avoid this issue there are alternative approaches for JavaFX development which may or may not suit you:

  • Create a Maven project rather than an Ant project in NetBeans.
  • Use an alternative IDE, such as IntelliJ IDEA offering a JavaFX template for new projects. See this Answer for details.
  • Regress to a much earlier version of NetBeans (12.0 or earlier) and use JDK 8.

One final point: although you can't build a JavaFX project generated by the wizard when using Ant, it is still possible to run the file containing the main() method that was generated by the wizard, using Run > Run File. Here's a screen shot showing that file being run after I made a couple of cosmetic changes in the code:

Run File

Of course that approach has limited value, but I mention it for completeness.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
skomisa
  • 16,436
  • 7
  • 61
  • 102