0

I tried to change TextArea into TextFlow to have colored texts in my chat application. With TextArea this code work fine. But with Textflow, I got exception messages.

    public void initialize()throws Exception{
        (new Thread() {
            public void run() {
                isClient = true;
                client = new Client(ip,userName,port){
                    public void display(CommandList command, String msg){
                        switch(command) {
                            case WELCOME:
                                textAreaMessages.getChildren().add(new Text("Welcome to SAND, "+userName+"\n"));

                                break;

                        }
                    }
                };
            }
        }).start();

I Tried also with Platform.runlater but it also didn't work.

 public void initialize()throws Exception{
        Platform.runLater(new Runnable() {
                public void run() {
                client = new Client(ip,userName,port){
                    public void display(CommandList command, String msg){
                        switch(command) {
                            case WELCOME:
                                textAreaMessages.getChildren().add(new Text("Welcome to SAND, "+userName+"\n"));
                                //enable text-input in chat
                                break;
                            case MESSAGE:
                                textAreaMessages.getChildren().add(new Text(msg+"\n"));
                                break;
                        }
                    }
                };
            }
        });
    }

This is the exception messages i got.

 Exception in thread "Thread-5" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-5
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
        at ClientController$1$1.display(ClientController.java:47)
        at Client$2.run(Client.java:167)
Syarif Mathis
  • 161
  • 1
  • 6
  • Possible duplicate of [java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4](http://stackoverflow.com/questions/29449297/java-lang-illegalstateexception-not-on-fx-application-thread-currentthread-t) – fabian Apr 01 '17 at 12:07
  • @JoëlAbrahams I tried also with platform.runlater (see edited question) but still got error. – Syarif Mathis Apr 01 '17 at 16:30
  • I solved the problem. I put each of the method that update the UI in Platform.runlater now it works fine. thanks for your help guys. – Syarif Mathis Apr 01 '17 at 16:44

0 Answers0