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 Design a Better App Add a node via FXML

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

Add a node via FXML

What am I doing wrong in this challenge? I don't understand what the problem is here. Can anyone help please?

com/example/boombox.fxml
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<VBox fx:controller="com.example.Controller"
      xmlns:fx="http://javafx.com/fxml">

    <!-- Add your element below -->
  <Text boombox="Boombox"
        GridPane.rowIndex="0"
        GridPane.columnSpan="2"
        Gridpane.halignment="CENTER"/>


    <Button text="Play"/>
</VBox>
com/example/Main.java
package com.example;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("boombox.fxml"));
        primaryStage.setTitle("Boombox");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
com/example/Controller.java
package com.example;

public class Controller {
}

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Lee;

First, for this challenge don't include GridPane settings. Second, the property you should be setting is the text property of the Text field, not the boombox property.

Post back with further questions.

Happy coding,
Ken

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

Thank you so much Ken. I was thinking that I was declaring a variable, that's why I had changed the name of it. I was thinking that if I had named the field "text" then it would have conflicted with the other field that was names text. Thank you again and Happy coding :)