0
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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

And how would I do that?
remplace import java.awt.Button; with import javafx.scene.control.Button;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.