如何更改文本字段中的文本?

时间:2014-09-08 09:31:40

标签: java javafx-2 textfield scenebuilder

我正在使用JavaFX Scene Builder来创建我的UI。我希望能够从其他类(主要来自有限状态机)更改位于我的SimpleController类中的文本字段中的文本。

@FXML public TextField textDescr;

我尝试过设置

public void setText(String s) {textDescr.setText(s);}
在SimpleController中

但是 Eclipse告诉我“不能对非静态方法进行静态引用”

SimpleController.setText("Some stuff");

2 个答案:

答案 0 :(得分:0)

您需要创建SimpleController

的实例

试试这个:

SimpleController sc = new SimpleController();
sc.setText("Some stuff");

答案 1 :(得分:0)

您正尝试静态访问您的设置文本方法。 SimpleController.setText("Some stuff");应为new SimpleController().setText("Some text");

相关问题