1

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){}}  
}
Yarl
  • 728
  • 1
  • 7
  • 26
  • Please edit your question to include a [mcve]; note that [this](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html) is required of applets, too. – trashgod May 03 '16 at 08:01
  • I have make some reasonable long sample of this behavior but because of its shortness you can see that *jp2launcher.exe* terminates with very little delay but definitely not terminates along with applet termination. – Yarl May 04 '16 at 08:35

1 Answers1

1

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);
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045