【发布时间】:2016-05-03 06:22:45
【问题描述】:
如果我关闭带有 JavaFX 内容的小程序(因此小程序正在使用 EDT 和 JavaFX 线程),jp2launcher.exe 将继续运行近 1 分钟,因此小程序无法再次轻松启动(一旦它未被识别为新实例 -浏览器关闭后等)。
我在 Google 上搜索过,但没有找到解决方案。我只发现了非常相似的问题——https://bugs.openjdk.java.net/browse/JDK-8051030。
另一个解决方案是,如果小程序可以在持久的 jp2launcher.exe 上启动,但它不能。它根本没有被调用。只覆盖了 JApplet 的 init 方法。
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import java.awt.Graphics;
import javafx.embed.swing.JFXPanel;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.animation.Timeline;
/*<applet code="sample" width=600 height=600></applet>*/
public class sample extends JApplet{
protected Scene scene;
protected Group group;
Timeline timeline;
JFXPanel fxPanel;
@Override
public final void init(){initSwing();}
private void initSwing(){
fxPanel = new JFXPanel();
add(fxPanel);
Platform.runLater(() ->{initFX(fxPanel);});
}
private void initFX(JFXPanel fxPanel){
timeline=new Timeline();
group=new Group();
scene=new Scene(group);
}
@Override
public void start(){
try{SwingUtilities.invokeAndWait(this::initSwing);}
catch(java.lang.InterruptedException|java.lang.reflect.InvocationTargetException e){}}
}
【问题讨论】:
-
请编辑您的问题以包含minimal reproducible example;请注意,小程序也需要this。
-
我已经对此行为做了一些合理的长示例,但是由于它的简短性,您可以看到 jp2launcher.exe 以非常短的延迟终止,但绝对不会随着小程序终止而终止.
标签: java swing javafx japplet jfxpanel