0

I am trying to close JavaFX custom dialog after some job is done, but It's not closing. I have tried everything what was on web. But still no success. I am using :

  import javafx.scene.control.Dialog;

Code:

 dialogProgressBar.progressIndicator().show();
 Service<Void> service = new Service<Void>() {
                @Override
                protected Task<Void> createTask() {
                    return new Task<Void>() {
                        @Override
                        protected Void call() throws Exception {
                            //Background work
                            mySqlDatabaseHandler.mySQLConnection();
                            mySqlDatabaseHandler.executeStatement();
                            closeConnection();
                            Platform.runLater(() -> {
                                //FX Stuff done here
                                dialogProgressBar.progressIndicator().close();
                            });

                            return null;
                        }
                    };
                }
            };
  service.start();
TheDude
  • 135
  • 4
  • 17
  • Use the Task's `onFinish()`. – SedJ601 May 08 '18 at 18:04
  • Does the "other FX stuff" get executed? – James_D May 08 '18 at 18:05
  • what you mean by other? Everything is working as expected. I am getting data and it's putting data into table while progress bar is loading, but after it reaches close(); nothing happens. – TheDude May 08 '18 at 18:08
  • 1
    @Sedrick there is no such method onFinish() there is done() and this is not working got error: Not on FX application thread; currentThread = Thread-4 – TheDude May 08 '18 at 18:10
  • You have a comment: "//FX Stuff done here": that's what I meant – James_D May 08 '18 at 18:10
  • 1
    There is `setOnSucceeded()`. – James_D May 08 '18 at 18:10
  • 1
    There is no real reason the code you posted shouldn't work; it's possible either that an exception is being thrown (and somehow squashed) before you get to the call to `close()`, or that there are problems elsewhere in your code that prevent this working properly. See if you can create a [MCVE] (i.e. something that is complete, so we can run it, **and** minimal, so it does nothing more than is necessary to reproduce the problem). Do you really need a `Service` here, BTW? Seems it would be enough just to create a `Task` and run it in a thread. – James_D May 08 '18 at 18:13
  • I have tried Service, Task, Thread. None of them is working. no exceptions have been thrown. – TheDude May 08 '18 at 18:14
  • 1
    How do you know no exceptions are thrown? If an exception is thrown from your `call()` method, you would not be informed of it. – James_D May 08 '18 at 18:15
  • I have created Service to get to JavaFX thread. – TheDude May 08 '18 at 18:15
  • as I said call() method is working fine it's doing what it's supposed to do. I debuged everyhting. Everything is going fine, but close() method is just passed and nothing happens. I assume because it's of JavaFX thread or smth. But I don't know atm how to solve it. – TheDude May 08 '18 at 18:17
  • Have a look at https://stackoverflow.com/questions/30249493/ for cleaner ways to structure this, that separate things out more clearly. I don't understand "I have created Service to get to JavaFX thread.": there is nothing in the code you posted that the service is giving you that you cannot do with a `Task`. – James_D May 08 '18 at 18:17
  • Again, not enough information in your question for it to be solved. Post a [MCVE]. – James_D May 08 '18 at 18:17
  • I made a simple thread with just some sout and dialog is still not closed. Information is more than enough. If you want I can write all possible solutions I've tried from all possible Stackoverflow answers. – TheDude May 08 '18 at 18:20
  • I tried it and it works fine for me. Therefore, clearly, the problem lies elsewhere in your code. – James_D May 08 '18 at 18:31
  • So let's take a look. Post it as an answer. – TheDude May 08 '18 at 18:44
  • But it's not an answer, because it doesn't actually answer anything in the stated question. It would be absolutely no use to any other users. – James_D May 08 '18 at 18:53

0 Answers0