JavaFX dynamic Text content for scene

I'm trying to learn some basic how to's for JavaFX in respect to Java and am confused on how to change the text in a scene as a result of a button press.

This is the code I was trying, but my new text never gets displayed. I haven't found an example on how to do something as basic as this anywhere in JavaFX tutorials.

How can I make the text say "New Scene Text" after clicking the button instead of "Starting Text".
package javafxbutton;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.control.Button;
import java.lang.System;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextOrigin;
import javafx.scene.paint.Color;


Stage {
    title: "Application title"
    scene: Scene {
        width: 250
        height: 120
        content: [
            VBox {
                layoutX: 20
                layoutY: 20
                spacing: 10
                content: [
                    Text {
                        textOrigin: TextOrigin.TOP
                        fill: Color.web("ox131021")
                        font: Font.font("Sans Serif", 14)
                        content: "Starting Text"
                    },
                    Button {
                        text: "Button Text"
                        action: function (): Void {
                            Text {
                                textOrigin: TextOrigin.TOP
                                font: Font {
                                    size: 16
                                }
                                content: "New Scene Text"
                            }
                            System.out.println("Button Text");
                        }
                    }
                ]
            }
        ]
    }
}

Open in new window

mitchguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

warsqlCommented:
I only know JavaFX in theory, but I believe you bind the display text to a variable, then just change the value when the button is clicked.  JavaFX manages keeping the display consistent with your variable because the value is bound.

var message = "Starting Text"
....

Text {
                        textOrigin: TextOrigin.TOP
                        fill: Color.web("ox131021")
                        font: Font.font("Sans Serif", 14)
                        content: bind message
                    },
Button {
                        text: "Button Text"
                        action: function (): Void {
                            message = "New scene text"
                        }
                    }
....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mitchguyAuthor Commented:
That worked perfectly. I need to try and stop thinking in Java/C++. I thought it was going to be something like
scene.content.myText = "new scene text"

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.