0

EDIT: I dont understand how Im changing the UI from the Task, I using a method form the controller to change the UI, how can I do this ? Please try using my examples and tell me if I need to add some Info

I'm trying to add text from a Task to a Text flow using a method in the controller class, for some reason the program fails on .getChildren() method .

Call for Spliter in the controller class:

btnSplit.setOnMouseClicked(new EventHandler<Event>() {
            @Override
            public void handle(Event event) {
                Thread split = new Thread(new Spliter(custToSplit, Controller.this));
                split.setDaemon(true);
                split.start();

            }
        });

class Spliter constractor :

public Spliter(File f, Controller c){
        this.c = c;
        this.cust = f;

    }
c.updateHebFlow("Dir created: "+ newDir.getAbsolutePath() , INFO_TEXT);

Part of the Controller class :

@FXML
    private TextFlow hebFlow;
@Override
    public void initialize(URL location, ResourceBundle resources) {
assert hebFlow != null : "fx:id=\"hebFlow\" was not injected: check your FXML file 'MainXml.fxml'.";

    public void updateHebFlow(String text,String type){
        normalText = new Text();
        errorText = new Text();
        errorText.setFill(Color.RED);
        infoText = new Text();
        infoText.setFill(Color.BLUE);
        switch(type){
        case(ERROR_TEXT) :
            errorText.setText(text);
            hebFlow.getChildren().addAll(new Text("/n"), errorText);
            break;
        case(INFO_TEXT) :
            infoText.setText(text);
            hebFlow.getChildren().addAll(new Text("/n"), infoText);
            break;
        case(NORMAL_TEXT) :
            normalText.setText(text);
            hebFlow.getChildren().addAll(new Text("/n"), normalText);
            break;
        }
    }   
}

The program works fine without the Textflow, it stops at the getChildren() method. Where is the mistake here?

edit: thanks to @James_D I forgot to catch exception in the task. I added to the method call in spliter :

try{
c.updateHebFlow("Script by TulTul", INFO_TEXT);
}catch (Exception e){
            e.printStackTrace();
        }

and I get:

java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
Gurman Eduard
  • 73
  • 1
  • 1
  • 8

0 Answers0