0

I am trying to put buttons in the bottom of my BorderPane and I keep getting an error, I have had it working before but now am getting an error "Exception in Application start method".

package assign3;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Question2 extends Application
{

    @Override
    public void start( Stage obPrimeStage ) throws Exception
    {
        Button btRed = new Button("Red");
        Button btGreen = new Button("Green");
        Button btBlue = new Button("Blue");
        Button btOrange = new Button("Orange");
        Button btStart = new Button("Start");

        BorderPane obBorder = new BorderPane();
        HBox obPane = new HBox();

        obPane.getChildren().add(btRed);
        obPane.getChildren().add(btGreen);
        obPane.getChildren().add(btBlue);
        obPane.getChildren().add(btOrange);
        obPane.getChildren().add(btStart);

        obBorder.setBottom(obPane);

        Scene obScene = new Scene(obPane, 400, 400);

        obPrimeStage.setTitle("Question 2");
        obPrimeStage.setScene(obScene);
        obPrimeStage.show();

        btRed.setOnAction((ActionEvent e) -> 
        {
            obPane.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
        });

        btGreen.setOnAction((ActionEvent e) -> 
        {
            obPane.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY)));
        });

        btBlue.setOnAction((ActionEvent e) -> 
        {
            obPane.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
        });



    }

    public static void main( String[] args )
    {
        Application.launch(args);

    }

}

I feel like it has something to do with obBorder.setBottom(obPane) but am not sure. Our instructor kind of glossed over all of this and I am having a hard time comprehending it even after looking at the javadoc.

Any help would be greatly appreciated.

Reg Smith
  • 166
  • 1
  • 15

1 Answers1

1

You can't add a node to another pane, and make it the root of the scene. (Read the stack trace: it tells you exactly what is going wrong.)

I think you meant

Scene obScene = new Scene(obBorder, 400, 400);

instead of

Scene obScene = new Scene(obPane, 400, 400);
Community
  • 1
  • 1
James_D
  • 201,275
  • 16
  • 291
  • 322
  • Oh.. my god. It has been a long day. Thank you! I think my eyes need a break. – Reg Smith Mar 13 '17 at 22:49
  • Again, anyone can make those kind of mistakes. That's why the stack trace includes the information to tell you what you did wrong. Read it. – James_D Mar 13 '17 at 22:50
  • Yep, that would do it. Haven't had to look at one before so I just saw a multitude of red lines and started to panic. Going through it now it makes much more sense. – Reg Smith Mar 13 '17 at 22:52
  • I added a link to the answer which contains a really nice description of how to read and diagnose a problem from the stack trace. Probably the most helpful thing on SO :). – James_D Mar 13 '17 at 22:53
  • You are a true hero. Thank you so much. – Reg Smith Mar 13 '17 at 22:54