jp2launcher.exe does not exits with applet closure

893 Views Asked by At

If I close applet with JavaFX content (so applet is using EDT and JavaFX thread) the jp2launcher.exe continues run for almost 1 minute so that applet cannot be easily started again (as soon as it is not recognized as new instance – after browser close etc.).

I have search Google but I have found no solution. I have found only very similar issue – https://bugs.openjdk.java.net/browse/JDK-8051030.

Another solution would be if the applet could start on lasting jp2launcher.exe but it cannot. It is simply not invoked. Only init method of JApplet is overriden.

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){}}  
}
1

There are 1 best solutions below

0
On

Based on your update,

  • I am unable to reproduce the problem on the platform shown; there is no perceptible increase in the delay between choosing to quit the applet and returning to the command prompt. In case the problem is platform specific, I've included the example as tested for reference.

    $ javac sample.java ; appletviewer sample.java
    
  • A noted here, "In an applet, the GUI-creation task must be launched from the init method using invokeAndWait." Applet::start is too late.

  • Unused to discarding exceptions, I see java.lang.IllegalStateException on quit when the JFXPanel is empty or uninitialized.

image

import javafx.embed.swing.JFXPanel;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;

/*<applet code="sample" width=300 height=200></applet>*/
public class sample extends JApplet {

    protected Scene scene;
    protected Group group;
    JFXPanel fxPanel;

    @Override
    public final void init() {
        try {
            SwingUtilities.invokeAndWait(this::initSwing);
        } catch (java.lang.InterruptedException | java.lang.reflect.InvocationTargetException e) {
            e.printStackTrace(System.out);
        }
    }

    private void initSwing() {
        fxPanel = new JFXPanel();
        add(fxPanel);
        Platform.runLater(() -> {
            initFX(fxPanel);
        });
    }

    private void initFX(JFXPanel fxPanel) {
        group = new Group();
        group.getChildren().add(new Label(
            System.getProperty("os.name") + " v"
            + System.getProperty("os.version") + "; Java v"
            + System.getProperty("java.version")));
        scene = new Scene(group);
        fxPanel.setScene(scene);
    }
}