Javafx不允许我setText()或add(),(仅添加节点)



我正在尝试构建一个简单的gui,而且我很确定我已经正确设置了构建路径(从youtube vid(,但是它不允许我使用'.setText(('或'.add((',但是它允许我在我的舞台上使用.settitle((?

我尝试使用Ctrl Space建议,但它仅为我提供'node(boolean('或node(int index,node element(。

    package application;
    import java.awt.Button;
    import javafx.application.Application;
    import javafx.stage.Stage;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    public class Main extends Application {
public static void main(String[] args) {
    launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
    // TODO Auto-generated method stub
    primaryStage.setTitle("this is a stage");
    Button button;
    button = new Button("click me");
    StackPane layout = new StackPane();
    layout.getChildren().add(button);
    primaryStage.show();
}
    }

错误:"类型列表中的方法添加(节点(不适用于参数(按钮("

但是,正如我上面说的,唯一的选择是节点?

您必须在舞台内添加一个场景。舞台只是一个容纳场景的容器,该场景容纳场景图(按钮,标签等(。添加您制作的布局作为这样的场景中的根节点

Scene scene = new Scene(layout);
stage.setScene(scene);

最新更新