java - JavaFX: how do I use concurrency to read the output of an external process and display it in an FXML TextArea? -


here simple example of problem. let's have java app displays gui using javafx. when user hits start button, app pings external server 15 seconds. idea during 15 seconds, output of ping process should appear in gui of app. have far:

1) mypackage/app.fxml file use build javafx layout. 2) mypackage/appcontroller.java file 3) mypackage/app.java file

in fxml file specify controller in appcontroller.java file when start button pushed. controller looks this:

@fxml private void handlestartaction(actionevent event) {     try {         string ping_command = "ping -c 15 google.com";         console.println("\ncommand> "+ping_command);         process p=runtime.getruntime().exec(ping_command);          p.waitfor();          bufferedreader reader=new bufferedreader(new inputstreamreader(p.getinputstream()) );         string line=null;         while((line=reader.readline())!=null)         {             console.println(line);         }     }     catch(exception e) {          console.println(e);     } } 

the problem having app hangs full 15 seconds while waiting external process complete, instead of reading output process appears, once per second.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -