The attached test case demonstrates that JFXPanel prevents a Swing application from terminating normally when all windows are disposed. System.exit must be called or a TERM signal must be sent using Control-C (if run at a command prompt) or by "kill -term <pid>". I have produced this in both Linux and Windows.
---------------------------------------------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class ShutdownBug {
public ShutdownBug() {
final JFrame frame = new JFrame("JavaFX 2 in Swing");
final JFXPanel jfxPanel = new JFXPanel();
frame.add(jfxPanel, BorderLayout.CENTER);
final JButton button = new JButton("Exit");
frame.add(button, BorderLayout.NORTH);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Platform.exit();
frame.dispose();
/* Process does not terminate without this or sending a TERM
* signal or pressing control-C. */
// System.exit(0);
}
});
final Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println("Running shutdown hook.");
}
};
final Thread shutdownThread = new Thread(runnable, "shutdown-hook");
Runtime.getRuntime().addShutdownHook(shutdownThread);
/* Neither makes a difference. */
// Platform.setImplicitExit(true);
Platform.setImplicitExit(false);
/* Closing the window has the same problem. */
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new ShutdownBug();
}
});
}
}
---------------------------------------------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class ShutdownBug {
public ShutdownBug() {
final JFrame frame = new JFrame("JavaFX 2 in Swing");
final JFXPanel jfxPanel = new JFXPanel();
frame.add(jfxPanel, BorderLayout.CENTER);
final JButton button = new JButton("Exit");
frame.add(button, BorderLayout.NORTH);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Platform.exit();
frame.dispose();
/* Process does not terminate without this or sending a TERM
* signal or pressing control-C. */
// System.exit(0);
}
});
final Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println("Running shutdown hook.");
}
};
final Thread shutdownThread = new Thread(runnable, "shutdown-hook");
Runtime.getRuntime().addShutdownHook(shutdownThread);
/* Neither makes a difference. */
// Platform.setImplicitExit(true);
Platform.setImplicitExit(false);
/* Closing the window has the same problem. */
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new ShutdownBug();
}
});
}
}
- relates to
-
JDK-8120268 Exception in PlatformImpl.checkIdle with glass thread checks enabled
-
- Resolved
-