如何在java fx 2中更改TextField的文本 [英] how to change the text of TextField in java fx 2
本文介绍了如何在java fx 2中更改TextField的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个TextField
,其中有一些文本,但是我想在某些事件中更改该文本,但是我得到了NullPointerException
.
I have a TextField
in which there is some text but I want to change that text on some event but I am getting the NullPointerException
.
我正在使用setText()
方法,但仍然无法正常工作.我正在从其他类中调用该函数.
I am using setText()
method but still its not working. I am calling that function from other class .
有帮助吗?
谢谢.
推荐答案
在控制器的类定义的开头:
At beginning of the controller's class definition:
@FXML private TextField txtDescription;
在initialize方法中,添加:
Within the initialize method, add:
txtDescription = new TextField();
在作用于该文本字段的方法中,类似于:
Within a method that acts on that text field, something like:
txtDescription.setText("This is my new text.");
这篇关于如何在java fx 2中更改TextField的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文