hhrzc
hhrzc

Reputation: 2050

JavaFX not stop application by stop() method

I have follow abstract class, with init() and stop() methods: (issue in stop() method)

public abstract class AbstractJavaFxApplication extends Application {

    private static String[] fxArgs;

    protected ConfigurableApplicationContext applicationContext;

    @Override
    public void init() throws Exception {
        applicationContext = SpringApplication.run(getClass(), fxArgs);
        applicationContext.getAutowireCapableBeanFactory().autowireBean(this);
    }

    @Override
    public void stop() throws Exception {
        System.out.println("STOP");
        applicationContext.stop();
        super.stop();
    }

    protected static void launchApp(Class<? extends AbstractJavaFxApplication> clazz, String[] args){
        fxArgs = args;
        Application.launch(clazz, args);
    }
}

And main class, which extends the AbstractJavaFxApplication:

@SpringBootApplication
public class WeightliftingviewerApplication extends AbstractJavaFxApplication{

    @Value("First attempt")
    private String tittle;

    @Qualifier("mainView")
    @Autowired
    private ControllersConfiguration.ViewHolder view;

    public static void main(String[] args) {
        launchApp(WeightliftingviewerApplication.class, args);
//      SpringApplication.run(WeightliftingviewerApplication.class, args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle(tittle);
        primaryStage.setScene(new Scene(view.getView()));
        primaryStage.setResizable(true);
        primaryStage.centerOnScreen();
        primaryStage.show();
    }
}

Issue in that, what, when I close application I expectedly will hit in stop() method and gets STOP in console. But application not stopped and yet running in process

Upvotes: 0

Views: 1103

Answers (1)

Mohamed Benmahdjoub
Mohamed Benmahdjoub

Reputation: 1280

Try this in your Stop Method :

@Override
public void stop() throws Exception {
    System.out.println("STOP");
    Platform.exit();
    System.exit(0);
}

Upvotes: 1

Related Questions