java - JavaFX thread does not die although I set Platform.setImplicitExit(true)? -


in application used javafx.stage.filechooser , javafx thread start. frame i set default close operation windowconstants.dispose_on_close. when user exit application gui disappear application continue running because of javafx thread still being alive. interesting thing i set platform.setimplicitexit(true); . documentation of function says:"if attribute true, javafx runtime implicitly shutdown when last window closed;", did not happen. problem solved setting default close operation windowconstants.exit_on_close or using javax.swing.jfilechooser instead of filechooser. i have fixed it, interested , understand why javafx thread did not shutdown though set implicit exit , nothing opened.

here small example program (click button->close file chooser->close application):

public class jfxproblm {     public static void main(string[] args) {         eventqueue.invokelater(() -> {             new myframe();         });     }      private static class myframe extends jframe {          public myframe() {             setvisible(true);             setbounds(150, 150, 300, 300);             setdefaultcloseoperation(windowconstants.dispose_on_close);             //windowconstants.exit_on_close->the application close,              //but not point of question             add(new jbutton(new abstractaction("file chooser") {                  @override                 public void actionperformed(actionevent arg0) {                      {                            // prepare toolkit                         new jfxpanel();                         platform.setimplicitexit(true);                     }                      final filewrapper f = new filewrapper();                     if (platform.isfxapplicationthread()) {                         filechooser fc = new filechooser();                         f.setf(fc.showopendialog(null));                     } else {                         synchronized (f) {                             platform.runlater(() -> {                                 synchronized (f) {                                     filechooser fc = new filechooser();                                     f.setf(fc.showopendialog(null));                                     f.notify();                                 }                             });                             try {                                 f.wait();                             } catch (interruptedexception e) {                                 throw new runtimeexception(e);                             }                         }                     }                      file file = f.getf();                     if(file!=null)                         joptionpane.showmessagedialog(null, f.getf().tostring());                  }             }));         }     }      /**      * used because of must final in runnable.      * if there better way please educate me :)      *      */     private static class filewrapper {         private file f = null;          public synchronized file getf() {             return f;         }          public synchronized void setf(file f) {             this.f = f;         }     } } 

i made small test , program not end, again because of javafx thread.

public class main {      public static void main(string[] args) {         new jfxpanel();         platform.setimplicitexit(true);         platform.runlater(()->{             filechooser fc = new filechooser();             fc.showopendialog(null);         });     }  } 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -