如何在 Windows 10 Eclipse 上安装 JavaFX?
How to install JavaFX on Windows 10 Eclipse?
我正在尝试在 Internet 上找到的一些说明,但它们太旧了,现在不能用于最新的 Eclipse IDE 版本。
我正在尝试的代码 运行:
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
我建议使用像 maven 或 gradle 这样的构建工具。在您的情况下,这些工具可用于管理诸如 javafx 之类的依赖项。
此外,您可以按照此处的说明操作 Eclipse:https://openjfx.io/openjfx-docs/(link 也有针对 maven 和 Gradle 的说明)。
终于找到了如何操作的视频:How to Set Up JavaFX to work in Eclipse 2020 version
那家伙是个超级英雄。几点:
当您从 https://gluonhq.com/products/javafx/ 下载并解压缩 Windows 版本的最新 JavaFX SDK 时,复制该文件夹在硬盘上的位置,您将需要它来设置向上指向该包内的 lib 文件夹的路径。
这是您需要为路径粘贴的代码:
--module-path “你通往 \javafx-sdk-15.0.1\lib 的路径”--add-modules javafx.controls,javafx.fxml
截至 03/11/2020 解决方案适用于 Eclipse 版本:2020-09 (4.17.0)
构建 ID:20200910-1200 和 javafx-sdk-15.0.1
https://www.youtube.com/watch?v=bk28ytggz7E
从 2021 年开始使用这个较短版本的 YouTube 对我来说很有效。
1 从 Eclipse MarketPlace 安装 JavaFX
2 下载并安装 JavaFx
3 在Eclipse中添加User Library指向步骤2中JavaFx的文件夹路径
我正在尝试在 Internet 上找到的一些说明,但它们太旧了,现在不能用于最新的 Eclipse IDE 版本。
我正在尝试的代码 运行:
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
我建议使用像 maven 或 gradle 这样的构建工具。在您的情况下,这些工具可用于管理诸如 javafx 之类的依赖项。
此外,您可以按照此处的说明操作 Eclipse:https://openjfx.io/openjfx-docs/(link 也有针对 maven 和 Gradle 的说明)。
终于找到了如何操作的视频:How to Set Up JavaFX to work in Eclipse 2020 version
那家伙是个超级英雄。几点:
当您从 https://gluonhq.com/products/javafx/ 下载并解压缩 Windows 版本的最新 JavaFX SDK 时,复制该文件夹在硬盘上的位置,您将需要它来设置向上指向该包内的 lib 文件夹的路径。
这是您需要为路径粘贴的代码: --module-path “你通往 \javafx-sdk-15.0.1\lib 的路径”--add-modules javafx.controls,javafx.fxml
截至 03/11/2020 解决方案适用于 Eclipse 版本:2020-09 (4.17.0) 构建 ID:20200910-1200 和 javafx-sdk-15.0.1
https://www.youtube.com/watch?v=bk28ytggz7E
从 2021 年开始使用这个较短版本的 YouTube 对我来说很有效。
1 从 Eclipse MarketPlace 安装 JavaFX
2 下载并安装 JavaFx
3 在Eclipse中添加User Library指向步骤2中JavaFx的文件夹路径