Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8115375

Swing application with JFXPanel does not terminate properly

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u10
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      Debian Linux, Windows XP, Windows 8

      Description

      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();
                  }


              });
          }


      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                art Artem Ananiev
                Reporter:
                mcdevjfx mcdev1 (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: