【问题标题】:Why doesn't button add to scene?为什么按钮不添加到场景中?
【发布时间】:2015-09-07 16:55:20
【问题描述】:
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.BorderPane;
import javafx.scene.layout.StackPane;


public class Main extends Application {

    Button button;  //Declare Button

    public static void main(String[] args) {
        launch(args); //calls application 
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        //comes from application pack
        primaryStage.setTitle("Title Of Window"); //Main Stage
        button = new Button (); //Creates Button 
        button.setLabel("Click Me");

        StackPane layout = new StackPane();
        layout.getChildren().add(button); //Button in Scene
        Scene scene = new Scene (layout, 300, 250); //Sets Scene
        primaryStage.setScene(scene); //Stage and Scene
        primaryStage.show(); 



    }

大家好,这是我第一次在 JavaFX 中创建东西,我想知道为什么我在 Scene 中的按钮没有添加到 Layout.GetChildren() 行中,它一直在添加下方显示红线。我正在使用 Eclipse IDE。

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    你已经导入import java.awt.Button,你必须在javafx包中导入Button类。

    【讨论】:

    • 我该怎么做?
    • 用导入 javafx.scene.control.Button; 替换 import java.awt.Button;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 2014-06-30
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多