简体   繁体   English

在JavaFX中单击按钮时更改TextBox中的文本

[英]Change the text in a TextBox on button click in JavaFX

I have this easy little form in my JavaFX application. 我的JavaFX应用程序中有这个简单的小表格。 I want to use a button to change firstNameText and firstNameText . 我想使用一个按钮来更改firstNameTextfirstNameText

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 = Label { 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. 您要创建2个新的文本框,而不是更新2个现有的文本框。

try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM