javaeclipsejavafxefxclipse

JavaFX Eclipse suggestion to import not present


I am just starting with JavaFX and for some reason, Eclipse does not suggest to import JavaFX stuff so I have to type it in manually. Example: javafx.scene.Group I typed in Group as a type and it suggested other things such as javax.swing.GroupLayout.Group image of suggestions

I'm not exactly sure, but I think maybe the fact that the JavaFX library is under Modulepath instead of Classpath has to do with it, but it only works if it is under Modulepath.

Help would be greatly appreciated, thanks!


Solution

  • I'm rewriting this answer, as @kleopatra pointed out it was inexact

    For suggestions to work, you need to have JavaFX on your project's build path.

    If you've created a plain Java project in Eclipse, with a module-info.java at it's source path root, then you need to add all the required jars to the module path:

    Then suggestions should work as expected, and imports will be automatically inserted at the top of your java files, but they will appear in error the first time you import anything from a given library module, as this module must also be required in your module-info.java. You can do that automatically with a quick fix ("Add 'requires javafx.something' to module-info.java") when hovering the import.

    Now there's a more straightforward way to create a JavaFX modular project in Eclipse, using Maven:

    After the wizard terminates, you've got a nice little project already setup with an application window and two FXML sample displays. You can start from there to build your own project.

    Maven archetype

    Maven JavaFX Version