我的 JavaFX 应用程序中有这个简单的小表单。
我想使用按钮来更改 firstNameText
和 firstNameText
。
我没有能力,我是新手。我尝试了下面的代码,我的错误在哪里?
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" };
}
};
最佳答案
您正在创建 2 个新文本框,而不是更新 2 个现有文本框。
尝试
action: function() {
lastNameText.text = "ciao";
firstNameText.text = "ciao";
}
关于java - 在 JavaFX 中单击按钮时更改文本框中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2645304/