How to convert a normal java project in intellij into a JavaFx project

后端 未结 5 1989
攒了一身酷
攒了一身酷 2020-11-29 07:35

I am currently using a normal java project (gradle project) and want to convert this into a JavaFx project without having to reimport the existing sources into a new Javafx

5条回答
  •  再見小時候
    2020-11-29 08:19

    One solution is to generate your code using Scene Builder, and then integrate it into your existing IntelliJ project. While it should be possible to import this as a module, you can also simply move the code to where it needs to be (making appropriate corrections to package statements, etc). If you notice that the javafx imports aren't recognized within your project, try this solution:

    First ensure that you've set up IntelliJ in general for JavaFX by following the intial steps in this tutorial. Note: Below I mention 1.8, but this should work with 1.7+. I recommend 1.8+.

    Second ensure that the existing project settings allow for javaFX use

    1. Open Project Structure
    2. Click on Project under the project settings pane
    3. Ensure that the Project SDK is 1.8+.

    Third Ensure that the modules are configured for a JDK supporting JavaFX

    1. Open Project Structure
    2. Click on Modules under the project settings pane
    3. Ensure that the module SDK being used supports javaFX, Again I use JDK 1.8 but it should work with 1.7.

    Also, please be aware that if you have a maven project, you may need to put your fxml in a particular location, "/main/resources/". Take a look at this.

    That worked for me, and I hope it helps you.

提交回复
热议问题