Javafx:TextField处理程序

我不知道为什么,但是类成员newContact没有得到任何数据,当我尝试打印它时,它会打印null。

这是代码:

public class CreatContact_Controller {
    @FXML
    private VBox vBox;

    private Contact contact;
    private ArrayList<String> newContact = null;
    private ArrayList<TextField> textFields = null;

    void initData(Contact contact) {
        this.contact = contact.clon();
        editFields();
    }

    private void editFields(){

        for(int loop = 0 ; loop < contact.getPlaceHolders().size() ; loop++){
            HBox hBox = new HBox();
            Label label = new Label("Add the new " + contact.getPlaceHolders().get(loop));
            TextField textField = new TextField();
            textField.setOnaction(getTextField);
            hBox.getchildren().addAll(label,textField);
            vBox.getchildren().add(hBox);
        }
    }

    private EventHandler<actionEvent> getTextField =
            new EventHandler<actionEvent>() {
                @Override
                public void handle(actionEvent event) {
                    newContact.add(((TextField)event.getsource()).getText());
                    System.out.println(((TextField)event.getsource()).getText());
                }
            };
}

如何修复以便增加文本字段的值?

hahahahaha2009 回答:Javafx:TextField处理程序

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2917370.html

大家都在问