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 Build a Pomodoro App Properties and Bindings

Kevin Faust
Kevin Faust
15,353 Points

question on ${controller.timerText}

Hey everyone,

When we have this code in our fxml file:

text="${controller.timerText}"

I believe we are binding the text of our fxml to that timerText in our controller file. However timerText doesn't exist in our controller file. There is mTimerText but that is a private field. Does it actually call the method below?:

public StringProperty timerTextProperty() {
        return mTimerText;
    }

or this one?

public String getTimerText() {
        return mTimerText.get();
    }

I believe one those two are being binded. However I cant seem to pinpoint which.

Also what was the reason we used StringProperty and SimpleStringProperty? In terms of, when would one use one and why?

Is it basically a string that has getters, setters, and that property method ^?

How come this is only in javaFX and not in normal java?

I feel that there is some sort of connect between StringProperty, binding in the fxml, and that property method^. If anyone could help clear up my confusion that would be great.

Thank you,

Kevin

1 Answer

Kevin Faust
Kevin Faust
15,353 Points

I rewatched it again and I believe I understand it now. We need to use a StringProperty in order to use the binding function. So when we write timerText, it automatically is referring to the timerTextProperty() method. And this so called JavaBeans is only used in javafx because we dont have fxml and therefore no binding in regular java.