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

后端 未结 5 1997
攒了一身酷
攒了一身酷 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:09

    I followed those steps

    • Create a new module in your existing intellij project (A)
    • Create a new JavaFx project elsewhere
    • Copy the code from the JavaFx project, namely Controller.java,Main.java and sample.fxml into your module in the (A) project under the src directory as in A/user-interface/src

    • You'll find an error in sample.fxml since it references the controller class as sample.Controller change it to 'Controller' only. it worked this way (as I removed the sample package folder

    • In (A) open the settings menu File | Project Structure | Modules
    • Select the user-interface module from the list on the left side of the settings window
    • Switch to the dependencies tab
    • Add your old non-gui module as a module dependency using the green + mark on the right-hand side
    • Now you can use the classes in the non-gui module, enjoy!

    note: you can skip the add module dependency and let intellij do it for you, just type a name of a class in the old module, alt+enter (the light bulb magic) -> add module depenency

提交回复
热议问题