Issue
I was trying some instructions I found on the internet, but they are too old to be of use now with the latest Eclipse IDE release.
The code I am trying to run:
package javafxbasics;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class ShowFlowPane extends Application
{
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane and set its properties
FlowPane pane = new FlowPane();
pane.setPadding(new Insets(11, 12, 13, 14));
pane.setHgap(5);
pane.setVgap(5);
// Place nodes in the pane
pane.getChildren().addAll(new Label("First Name:"),
new TextField(), new Label("MI:"));
TextField tfMi = new TextField();
tfMi.setPrefColumnCount(3);
pane.getChildren().addAll(tfMi, new Label("Last Name:"),
new TextField());
// Create a scene and place it in the stage
Scene = new Scene(pane, 200, 250);
primaryStage.setTitle("ShowFlowPane in Java FX"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
Error: Unable to initialize main class javafxbasics.ShowFlowPane in module JavaFXproject Caused by: java.lang.NoClassDefFoundError: Stage
Solution
Finally found a video how to do that: How to Set Up JavaFX to work in Eclipse 2020 version
That guy is a superhero. A couple of points:
when you download and unzip the latest JavaFX SDK for Windows release from https://gluonhq.com/products/javafx/, copy the location of that folder on your hard drive, you will need it to set up the path to the lib folder inside that package.
Here is the code which you will need to paste for the path: --module-path "your path to \javafx-sdk-15.0.1\lib" --add-modules javafx.controls,javafx.fxml
As of 03/11/2020 solution works with Eclipse Version: 2020-09 (4.17.0) Build id: 20200910-1200 and javafx-sdk-15.0.1
Answered By - Alan Shore
Answer Checked By - Candace Johnson (JavaFixing Volunteer)