3 Replies Latest reply: Nov 19, 2012 11:09 AM by jsmith RSS

    JavaFX - Timers and application termination

    974949
      Hello,

      I need to do a job in the background with several seconds of delay after the user presses a key (a delayed search to be more precise). To do this, I use a java.util.Timer, but since including it the application does not exit correctly after the last window is closed.

      To reduce the problem to the minimum expression, I've created this applicacion that shows the problem (eclipse shows it is still running after pressing close button):

      public class ApplicationClosing extends Application {

           private final Timer timerFiltro = new Timer();

           public static void main(final String[] args) {
                Application.launch(args);
           }

           @Override
           public void start(final Stage primaryStage) {
                Group root = new Group();
                Scene scene = new Scene(root, 400, 250, Color.WHITE);
                BorderPane borderPane = new BorderPane();
                borderPane.setCenter(new Label("Hello"));
                root.getChildren().add(borderPane);
                primaryStage.setScene(scene);
                primaryStage.show();
           }
      }

      If a comment the line of the Timer, the application ends correctly. Any ideas?

      Thank you all for your help :)