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 Separating the Layout

Jimmy Palelil
Jimmy Palelil
9,565 Points

no label text displayed while running the code

<?import javafx.geometry.Insets?> <?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.TextField?> <?import javafx.scene.text.Text?> <GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"> <Text text="Sup" GridPane.rowIndex="0" GridPane.columnSpan="2" GridPane.halignment="CENTER"/>

<Label
       GridPane.rowIndex="1"
       GridPane.columnIndex="0"><text>First Name:</text></Label>

<TextField
       GridPane.columnSpan="1"
       GridPane.rowIndex="1" />

<Button text="Say Sup!"
        GridPane.rowIndex="2"
        GridPane.columnIndex="1"
        GridPane.halignment="RIGHT" />

</GridPane>

2 Answers

Try this:

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.TextField?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">

    <Text text="Sup"
          GridPane.rowIndex="0"
          GridPane.columnSpan="2"
          GridPane.halignment="CENTER" />

    <Label text="Frist Name:"
            GridPane.rowIndex="1"
            GridPane.columnIndex="0"/>

    <TextField
            GridPane.rowIndex="1"
            GridPane.columnIndex="1"/>

    <Button text="Say Sup!"
            GridPane.rowIndex="2"
            GridPane.columnIndex="1"
            GridPane.halignment="RIGHT"/>

</GridPane>