尝试删除形状时出现JavaFX错误 [英] JavaFX error when trying to remove shape

查看:479
本文介绍了尝试删除形状时出现JavaFX错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果它被移动到屏幕的某个部分内,我试图从我的窗口中删除一个矩形。

I'm trying to remove a Rectangle from my window if it is moved to be inside of a certain part of the screen.

这是我的错误得到:


线程中的异常Thread-1539java.lang.IllegalStateException:不在FX应用程序线程上; currentThread = Thread-1539
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:238)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java :400)
at javafx.scene.Parent $ 1.onProposedChange(Parent.java:245)
at com.sun.javafx.collections.VetoableObservableList.remove(VetoableObservableList.java:172)
at com.sun.javafx.collections.ObservableListWrapper.remove(ObservableListWrapper.java:263)
at com.sun.javafx.collections.VetoableObservableList.remove(VetoableObservableList.java:179)
at MovementSample $ HandListener .onFrame(MovementSample.java:136)
at com.leapmotion.leap.LeapJNI.SwigDirector_Listener_onFrame(LeapJNI.java:495)

Exception in thread "Thread-1539" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-1539 at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:238) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:400) at javafx.scene.Parent$1.onProposedChange(Parent.java:245) at com.sun.javafx.collections.VetoableObservableList.remove(VetoableObservableList.java:172) at com.sun.javafx.collections.ObservableListWrapper.remove(ObservableListWrapper.java:263) at com.sun.javafx.collections.VetoableObservableList.remove(VetoableObservableList.java:179) at MovementSample$HandListener.onFrame(MovementSample.java:136) at com.leapmotion.leap.LeapJNI.SwigDirector_Listener_onFrame(LeapJNI.java:495)

这是导致问题的代码片段:

This is the snippet of code that cause the issue:

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

其中areOverlapping()只是一种检查某些方法的方法逻辑 - 问题不存在。

where areOverlapping() is just a method that checks some logic - the issue isn't there.

我的问题是:如果我有场景,如何从屏幕上删除一个矩形。另外,我在代码中做错了什么?

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

推荐答案

错误说明了


IllegalStateException:不在FX应用程序线程上

IllegalStateException: Not on FX application thread

您正在尝试进行的操作应该在JavaFX应用程序线程上完成,而你不在它上面。

You are trying to do an operation which should be done on JavaFX Application thread and you are not on it.

为了在 JavaFX应用程序线程上执行操作,用 Platform.runLater

In order to execute things on JavaFX Application thread, surround them with Platform.runLater

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

有关在JavaFX中修改UI组件

这篇关于尝试删除形状时出现JavaFX错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆