Do I need to update a property in the main thread?

I get an odd error at random times from this line of code:

playHead.setValue(atTime)(playHead is SimpleObjectProperty)

playHeadused as part of Bindingwhich element GUI(a TableView) relies on for its meaning. Does this mean that at any time it is playHeadupdated, it should be in the main thread?

As in, should it be:

javafx.application.Platform.runLater(new Runnable() {
    @Override
    public void run() {
        playHead.setValue(atTime);                  
    }
});

This seems odd since the class containing playHeadshould work independently of the GUI. Is there a way to define a binding so that it runs in the main thread? That way I can support good design methods.

Here is the callback for TableViewwhich returns the binding:

public class CuePreWaitCallback implements Callback<TableColumn.CellDataFeatures<Cue,String>, ObservableValue<String>> {

    @Override
    public ObservableValue<String> call(final CellDataFeatures<Cue, String> param) {
        final Timeline preWait = param.getValue().getCueTimeline().getPreWait();
        return new StringBinding() {
            {
                super.bind(param.getValue().getCueTimeline().getPreWait().playhead());
                super.bind(param.getValue().getCueTimeline().getPreWait().waitTime());
            }

            @Override
            protected String computeValue() {
                try {
                    System.out.println("Value Called---------------------------------------------->");
                    return preWait.getAbsoluteDuration().subtract(preWait.getPlayhead()).toString();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(0);
                    return "";
                }

            }
        };
    }

}
+1
1

, , (, ), , runLater , .

, , "" , , ; . -, runLater .

, - "", "", - .

0

All Articles