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 project. Is there any way to achieve this?
Click on the File menu and select Project Structure . In the dialog that appears, select the Libraries tab and click the + icon to add a new Java library: Find your javafx-sdk folder and select the lib subfolder: Click the OK button to complete the process.
Go to File -> Project Structure -> Libraries and add the JavaFX 18 SDK as a library to the project. Point to the lib folder of the JavaFX SDK. Once the library is applied, the JavaFX classes will be recognized by the IDE.
There is nothing to convert.
I don't believe there is any difference in Idea between a "normal" Java project and a JavaFX project.
Sure, in Idea 12.x+ there is a wizard you can use to create a new JavaFX project. But I think that all it does is create a sample hello world application - after initial creation, the way the project works is not any different than any other Java project.
And this is how it should be, JavaFX is just Java. Oracle doesn't differentiate between JavaFX and Java in their distribution, and neither should IDEs in their project types.
I believe, in this case, even if I'm wrong, that I am right enough that it doesn't really matter if I'm wrong.
Update
So I was wrong enough that it matters :-)
Using Idea 13.1.4, if I create a new project using File | New Project | Java
, there are the following resource settings (File | Settings | Compiler
):
?*.properties;?*.xml;?*.gif;?*.png;?*.jpeg;?*.jpg;?*.html;?*.dtd;?*.tld;?*.ftl
That is, the resources for the project are just set to copy only specific file types. So you could modify it to get the additional file types required in some JavaFX projects by adding resource copying support for fxml and css; i.e, appending ;?*.fxml;?*.css
.
The interesting part is that if you create a new project using File | New Project | JavaFX
, there are the following resource settings:
!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj
Essentially, it's copying everything which not a source file, a kind of file blacklist set rather than a file whitelist set as is used by other project creation templates. Really weird... Anyway, the resource sets are user configurable, so you can modify them as you see fit and once you do so, you shouldn't have any issues (I believe, but I've been wrong before ;-)
Suggestion - Use 3rd party build tools in conjunction with your IDE
You might be better off basing your build off of a 3rd party tool such as Gradle or Maven. Idea works really well with both these external build tools (and others). The advantages of using a 3rd party tool is:
Of course, the disadvantage of using a 3rd party build tool, is the complexity (and many quirks) of learning them as sometimes they can be quite the beast. So I think it's a bit of a tradeoff - small, personal exploratory projects don't need them, larger projects or projects you intend to share with others benefit from using such tools.
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
Third Ensure that the modules are configured for a JDK supporting JavaFX
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With