gpt4 book ai didi

java - 为什么我只能在应用程序启动调用中初始化 JavaFX HTMLEditor?

转载 作者:行者123 更新时间:2023-12-02 05:17:30 25 4
gpt4 key购买 nike

如果我放置此代码

new HTMLEditor();

除了在我的 Application.start(Stage stage) 实现之外的任何地方,我都会收到以下错误:

SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: HTMLEditor[id=null], name: skinClassName, value: com.sun.javafx.scene.web.skin.HTMLEditorSkin]' for control HTMLEditor[id=null]
java.lang.IllegalStateException: Not on FX application thread; currentThread = main
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:238)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:400)
at javafx.scene.Scene.<init>(Scene.java:293)
at javafx.scene.Scene.<init>(Scene.java:201)
at javafx.stage.PopupWindow.<init>(PopupWindow.java:110)
at javafx.scene.control.PopupControl.<init>(PopupControl.java:98)
at javafx.scene.control.Tooltip.<init>(Tooltip.java:143)
at com.sun.javafx.scene.web.skin.HTMLEditorSkin.addButton(HTMLEditorSkin.java:785)
at com.sun.javafx.scene.web.skin.HTMLEditorSkin.populateToolbars(HTMLEditorSkin.java:470)
at com.sun.javafx.scene.web.skin.HTMLEditorSkin.<init>(HTMLEditorSkin.java:235)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at javafx.scene.control.Control.loadSkinClass(Control.java:1044)
at javafx.scene.control.Control.access$500(Control.java:70)
at javafx.scene.control.Control$12.invalidated(Control.java:972)
at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:127)
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:161)
at com.sun.javafx.css.StyleableStringProperty.set(StyleableStringProperty.java:71)
at javafx.scene.control.Control$12.set(Control.java:964)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:59)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:31)
at com.sun.javafx.css.StyleableProperty.set(StyleableProperty.java:70)
at com.sun.javafx.css.StyleableProperty.set(StyleableProperty.java:76)
at javafx.scene.web.HTMLEditor.<init>(HTMLEditor.java:29)
at com.vasolsim.tclient.TeacherClient.initHTMLEditor(TeacherClient.java:134)
at com.vasolsim.tclient.element.form.QuestionInitNode.redrawNode(QuestionInitNode.java:53)
at com.vasolsim.tclient.element.form.QuestionInitNode.<init>(QuestionInitNode.java:33)
at com.vasolsim.tclient.TeacherClient.initializeStaticAssets(TeacherClient.java:172)
at com.vasolsim.tclient.TeacherClient.main(TeacherClient.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

当我在启动方法中创建对象时,一切正常。

有人有什么想法吗?

谢谢,-将

最佳答案

您需要位于 FX 应用程序线程(在启动应用程序时创建)上才能初始化 FX 对象。

如果您需要在运行时在 Application 代码之外初始化此类对象,您可以将代码包装在 Platform.runLater() 调用中。

Platform.runLater(new Runnable() {
@Override
public void run() {
// add your init here
}
});

这将安排您的任务在下次执行时在 FX 应用程序线程上运行(实际上,在未来的某个未指定的时间...)。 See reference .

关于java - 为什么我只能在应用程序启动调用中初始化 JavaFX HTMLEditor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26794785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com