java - JavaFX, order of commands (seemingly) ignored -


i'm programing in javafx under java1.7, , works code except part. problem is, end result gets written out. while program runs, want display "ping test running" text in label. won't that, instead waits couple of seconds (till ping finishes), writes out result of ping. looks bad, cause 3-4 secs nothing happens , user can think froze or something... hence message want write out. so, can tell me why happening , how fix it? thank time. ps: yes needs wait few secs, in pingip(...), can read needed info correctly, otherwise i'm getting null pointer error.

@fxml private label ping;  @fxml     private void button(actionevent event) throws ioexception {         string text;         ping.setwraptext(true);         ping.settext("ping test running");         text = pingip.pingwifiaddr(getip.retipwifi()).tostring();         text = text.substring(1, (text.length()-1));         teltonikaping.setwraptext(true);         teltonikaping.settext(text);     } 

below edited part

@fxml     private void ciscobutton(actionevent event) throws ioexception {         ciscoping.setwraptext(true);         task<void> task1 = new task<void>() {             @override public void call() throws ioexception {         string text1;         text1 = "ping teszt folyamatban";         ping.setwraptext(true);                 ping.settext(text1);                 return null;      } }; new thread(task1).start();          task<void> task = new task<void>() {             @override public void call() throws ioexception {                 string text2 = pingip.pingetheraddr(getip.retipether()).tostring();                 text2 = text2.substring(1, (text2.length() - 1));                 ping.setwraptext(true);                 ping.settext(text2);                 return null;             }         };         new thread(task).start();     } 

above edited one, ideas?

the reason because you're doing of work on javafx application thread. when set attribute, label's text, on javafx application thread results don't displayed. instead, waits until code finished running, @ point framework takes on again , can display changes.

in order around this, need execute long running code on separate thread, avoid blocking redrawing of gui. take @ concurrency in javafx details on how implement that.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -