Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application Graphical User Interfaces Adding Interactivity

Tony Gemenie
Tony Gemenie
3,781 Points

VBox not displaying

Hey Guys I think I might have an issue with my IDE. I'm working through the JavaFX program with Craig and can't seem to get the code to render correctly. It's verbatim what's in the video. The problem I'm seeing on my end: The Scene is not setting up correctly. It renders as if the VBox is not present.

Tony Gemenie
Tony Gemenie
3,781 Points

I'm still not getting a layout to show up on my intellJ idea install. I'll include the code for your reference. Another strange thing. When searching for {idea stage javafx not working} I'm only recieving 169 results from both google and Duck Duck Go. Any Ideas what might be going on or who to kill/shoot first?

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;



public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        //Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        Group root = new Group();
        Text txt = new Text("Sup");
        TextField nameFld = new TextField();
        Button btn = new Button();
        btn.setText("Say Sup!");
        btn.setOnAction(evt -> System.out.printf("Sup %s!%n",
                nameFld.getText()));
        txt.setY(50);
        VBox box = new VBox();
        box.getChildren().addAll(txt, nameFld, btn);
        root.getChildren().add(txt);
        root.getChildren().add(btn);
        primaryStage.setTitle("Sup");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


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

1 Answer

Deneen Edwards
Deneen Edwards
5,626 Points

comment out: root.getChildren().add(btn); root.getChildren().add(txt);

and substitute in: root.getChildren().add(box);