2 Replies Latest reply on Aug 19, 2013 7:49 AM by csh

    Implicit exit does not work, when you use AWT for SystemTray




      normally my JavaFX application exits the JVM automatically, when the last window is closed. (Platform.setImplicitExit(true) is the default)


      But as soon as I use AWT for displaying a System Tray icon, it doesn't anymore.

      Seems as if the AWT thread continues running.


      Does anybody know how to do it?


      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.stage.Stage;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      public class TestApp5 extends Application {
          public static void main(String[] args) throws Exception {
          public void start(final Stage stage) throws Exception {
              Label root = new Label("test");
              SystemTray.getSystemTray().add(new TrayIcon(new BufferedImage(16, 16, BufferedImage.TYPE_3BYTE_BGR)));
              Scene scene = new Scene(root);
        • 1. Re: Implicit exit does not work, when you use AWT for SystemTray

          If you use AWT in your application you have at least two threads.  The native part of AWT runs on one thread and the Java part runs on another one.  When you exit your Java part, the native part of AWT is still running.

          The javafx application without AWT has a single javafx application thread.

          If javafx had a system tray icon you would not have this issue.

          I suggest adding the following to resolve it.

          stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
           public void handle(WindowEvent e) {

          It works for me.

          I hope someday we will have system tray icon functionality in javafx8.

          You may want to vote for the javafx system tray api https://javafx-jira.kenai.com/browse/RT-24251

          • 2. Re: Implicit exit does not work, when you use AWT for SystemTray

            Yes that works of course.


            But I thought maybe there is something like


            AWTThread.cancel() or SwingUtilities.setImplicitExit(true).


            I also tried


            SwingUtilities.invokeLater(new Runnable(){




            It seems to work, but it throws an IllegalStateException nonetheless.


            Shutting down the JVM doesn't seem like the best option. Maybe you want other threads to finish their work.