el mashrafi
el mashrafi

Reputation: 182

Why doesn't button add to scene?

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(); 



    }

Hey guys, so this is first time I am creating something in JavaFX and I was wondering why doesn't my button in Scene add in Layout.GetChildren() line, it keeps on displaying red line underneath add. I am using Eclipse IDE.

Upvotes: 0

Views: 1710

Answers (1)

KarimS
KarimS

Reputation: 3892

you have imported import java.awt.Button, you must import Button class in the javafx package.

Upvotes: 2

Related Questions