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)