Cristina Fierbinteanu
Cristina Fierbinteanu

Reputation: 53

How to create a JavaFX module in IntelliJ IDEA

I would like to integrate a JavaFX GUI in an existing IntelliJ IDEA Java project (java version 1.8.0_20).

Although I can create a JavaFX project from scratch (JavaFX plugin is enabled) in my IDE, I can't figure out how to create a module.

Do I need to define a new module SDK for a new Java module? Or does the type of the JavaFX module has to be IntelliJ Platform Plugin? I tried both without any success. Please help.

Many thanks, Cristina

Upvotes: 7

Views: 6388

Answers (2)

jewelsea
jewelsea

Reputation: 159321

Update for Idea 2021.3

The previous information on this answer for Idea 13.1 is now outdated.

For Idea 2021.3, create a new JavaFX project using an Idea wizard:

  • New JavaFX project wizard.

    1. From the main menu, select File | New | Project.

    2. In the New Project wizard, select JavaFX from the list on the left.

I advise you follow the detailed instructions for creation and execution of JavaFX project at the new JavaFX project wizard link supplied.

A new JavaFX project created this way will be different from creating a new Java project using the same wizard. The new JavaFX project will be configured to use a build tool (e.g. maven or gradle). It will have the JavaFX module dependencies defined and will include sample code for a modular HelloWorld JavaFX FXML application. It is the perfect thing to use to get started with a new JavaFX application IMO.

If you want a new Idea module rather than a new project, then you just follow the same steps as above, but instead of selecting File | New | Project, you select File | New | Module, then select JavaFX from the list on the left as before.

Alternatively, you can create new modules in Idea by defining the modules in a Maven or Gradle project and importing the build tool project file for the project into Idea.

Prior answer for Idea 13.1

I don't think you can define a new JavaFX module in Idea 13.1. Note that there is not much difference between a JavaFX project and a non-JavaFX project in Idea, so you can just create a normal Java module and make a couple of manual tweaks to the module configuration and it should behave the same as if you created a JavaFX project. See the following answer for more details:

Upvotes: 5

Fuzail
Fuzail

Reputation: 413

Okay this question is old and has been answered but let me add more to it. I came across the same problem and did a little workaround:

You first open the main project in IDEA (in which you want to add a JavaFX project module), then goto File -> New -> Project.

From there, you get the standard New Project dialog of IDEA, so select javaFX and proceed. Make sure the project location is where you want the JavaFX module to be created (which is why i prompted you to open the parent project in IDEA first). Open it in a new window and close it, doesn't matter.

Now, (Assuming that you only have the main project opened in IDEA) goto its File -> Project Structure and in the dialog, goto Modules and click add (+) -> Import module and then select the project you just created. Proceed through the wizard, overwrite the .iml and the JavaFX module should be added to your main project structure.

Upvotes: 0

Related Questions