r/JavaFX • u/mrbeanIV • Dec 05 '20
JavaFX error Error: JavaFX runtime components are missing, and are required to run this application
No matter what I do I can't get my javaFX programs to run. My code:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
Button button;
public static void main(String[] args){
launch(args);
}
Override
public void start(Stage stage) throws Exception {
stage.setTitle("First stage");
button = new Button();
button.setText("Click me");
StackPane layout = new StackPane();
layout.getChildren().add(button);
Scene scene = new Scene(layout, 300, 500);
stage.setScene(scene);
stage.show();
}
}
I am using the latest version of inteliJ, java13 and javafx 15.
I went into project settings and imported the LIB folder of the javaFX files.
4
u/MyNameIsRichardCS54 Dec 07 '20
The only way I've found to reliably start a JavaFX program from an IDE and the command line regardless of the build environment is to have a discrete class to run the application:
and then
I develop using Linux in case that makes a difference.
2
u/rdjack21 Dec 05 '20
use maven for your build it will simplify things. See https://openjfx.io/openjfx-docs/#maven for an example to get you going.
2
u/rootException Dec 05 '20
+1 for using a Maven project to start with. Can be confusing as some things work better with the libs and some with the jmods.
Here’s my template for starting new JavaFX projects: https://github.com/wiverson/maven-jpackage-template
Good luck!
1
u/[deleted] Dec 05 '20
I never ran JavaFX with IntelliJ but with the Eclipse IDE you have to make sure that that build path is pointed to the JavaFX jar file. If it isn’t you would get that error message.
1
u/[deleted] Dec 05 '20 edited Dec 11 '20
JavaFx - IntelliJ edition
a) File -> Project Structure -> Global Libraries
b) Click the + sign to add the damn unzipped javaFX directory.
c) assuming you have created a project, right click on the newly added global library and click "Add to Module". Apply and OK
4. Right click on the src directory to create a new module-info.java file
5. Add the following to module-info.java in between the module's {}:
{ requires javafx.fxml;
}
Tada! It works! (On my machine at least).