开发者

Change the text in a TextBox on button click in JavaFX

开发者 https://www.devze.com 2022-12-27 13:17 出处:网络
I have this easy little form in my JavaFX application. I want to use a button to change firstNameText and firstNameText.

I have this easy little form in my JavaFX application. I want to use a button to change firstNameText and firstNameText.

I'm not capable, I'm a newbie. I tried the code below, where is my mistake?

def lastNameLabel = Label { text: "Last Name" };
def firstNameLabel = Lab开发者_如何学运维el { text: "First Name" };
var lastNameText = TextBox { text: "Last Name" };
var firstNameText = TextBox { text: "First Name" };

def cancelButton = Button { 
    text: "Cancel" 
    action: function() {
        lastNameText = TextBox { text: "ciao" };
        firstNameText = TextBox { text: "ciao" };

    }

};


you are creating 2 new textboxes instead of updating your 2 existing ones.

try

action: function() {
    lastNameText.text = "ciao";
    firstNameText.text = "ciao";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消