【发布时间】:2021-02-16 02:58:15
【问题描述】:
我尝试了一些在 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);
}
}
错误:无法在模块 JavaFXproject 中初始化主类 javafxbasics.ShowFlowPane 引起:java.lang.NoClassDefFoundError: Stage
【问题讨论】:
-
使用 Java 8 启动
-
您不认为从官方文档开始而不是从互联网上随意抓取一些东西更有意义吗? openjfx.io/openjfx-docs