JavaFX error while trying to delete form

I am trying to remove a rectangle from my window if it is moved to a specific part of the screen.

This is the error I received:

Exception in thread "Thread-1539" java.lang.IllegalStateException: not in FX application thread; currentThread = Thread-1539 on com.sun.javafx.tk.Toolkit.checkFxUserThread (Toolkit.java:238) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread (QuantumToolkit.javasew00.sceneaf Parent $ 1.onProposedChange (Parent.java:245) at com.sun.javafx.collections.VetoableObservableList.remove (VetoableObservableList.java:172) at com.sun.javafx.collections.ObservableListWrapper.remove (ObservableList26rapper com.sun.

This is the piece of code that causes the problem:

if(areOverlapping(sauceRectangle, pizzaInside)) { if(isHolding == null) { Group g = (Group) scene.getRoot().getChildrenUnmodifiable().get(1); g.getChildren().remove(sauceRectangle); } } 

where areOverlapping () is just a method that checks some logic - there is no problem there.

My question is this: how to remove a rectangle from my screen if I have a scene. Also, what did I do wrong in my code?

0
java javafx illegalstateexception
source share
1 answer

The error says it

IllegalStateException: not for FX application thread

You are trying to perform an operation that must be performed in a JavaFX Application, and you are not using it.

To perform actions on the JavaFX Application thread , surround them with Platform.runLater

 Platform.runLater(new Runnable() { @Override public void run() { //Code to be executed on JavaFX App Thread } }); 

For More Information on Changing UI Components in JavaFX

+2
source share

All Articles