简体   繁体   English

JavaFX如何将TextProperty绑定为附加到TextField(未设置)

[英]JavaFX how to bind TextProperty to append to TextField (not to set)

I have a TextField named eventLog with binded StringProperty from the other Class. 我有一个名为eventLog的TextField,具有来自其他类的绑定StringProperty。 This class looks like this: 这个类看起来像这样:

public class LogInfo {
    private static StringProperty logData = new SimpleStringProperty();

    public static StringProperty logDataProperty() {
        return logData;
    }

    public static void setLogData(String data) {
        logData.set(data);
    }

    public static String getLogData() {
        return logData.get();
    }
}

On my JavaFX controller class it's started like this: 在我的JavaFX控制器类上,它是这样开始的:

@Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        eventLog.textProperty().bind(LogInfo.logDataProperty());
        LogInfo.setLogData("Some informations");
    }

It's working great, but each time I use LogInfo.setLogData(String data) it's added to my TextField and clearing previous info, I need to append it. 它工作得很好,但是每次我使用LogInfo.setLogData(String data)时,它都会添加到我的TextField中并清除以前的信息,我需要附加它。 Is there any way to append instead of adding and clearing TextField ? 有什么方法可以添加而不是添加和清除TextField吗?

Since you can play with the output of the StringProperty, i recommend you this way: 由于您可以使用StringProperty的输出,因此我建议您这样做:

public static void setLogData(String data) {
    logData.set(logData.get()+data);
}

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

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