multithreading - JavaFX Popup needs to be called from javaFX GUI thread? -


i've got controller connected fxml-file several buttons, labels, table, etc. i've got popups initialized , shown when different buttons clicked , works fine.

i've got popup i'd 'pop up' when goes wrong, called when event get's handled has been sent java-code in class.

this message pop-up get's called, code within platform.runlater() isn't executed, freezing gui.

there's 1 distinction i've found seems cause , platform.isfxapplicationthread() call right before platform.runlater() returns false in message pop-up returns true when 1 of other pop-ups called button-click.

as i've tried 1 of pop-ups that's called button-click , doesn't work when it's called code get's executed because of incoming event, i'm pretty sure problem, platform.runlater states "this method, may called thread, post runnable event queue , return caller." , seems not true me, i'm kinda puzzled if problem ...

has encountered before , / or know i'm doing wrong?

this works fine:

@fxml private void btncashclicked(actionevent event) {     screenscontroller.getcashtransactioncontroller().addcashtransactionlistener(this);     labeltopay = new label(eurostopay + " euro");     sealbagtextfield = new sealbagtextfield();     popuputils.showcashpaymentpopup(btnsealbag, btncashok, labelpaid, labelsealbag, labeltopay, lblexchange,             labelexchange, labelreturnvalue, eurostopay, btncash, this, sealbagtextfield);     screenscontroller.getmaincontroller().starttransaction(amountincents, paymenttype.asap); } 

this code in same controller class doesn't show pop-up:

@override public void showerroronscreen(string message) {     // temporary usage of label , textfield     labeltopay = new label(eurostopay + " euro");     sealbagtextfield = new sealbagtextfield();     popuputils.showcashpaymentpopup(btnsealbag, btncashok, labelpaid, labelsealbag, labeltopay, lblexchange,             labelexchange, labelreturnvalue, eurostopay, btncash, this, sealbagtextfield);     //popuputils.showmessagepopup("error", message, "close", 374, 250, btncancel); } 

i'm on windows , using jre1.8.0_60

the code of cashpopup:

public static int showcashpaymentpopup(button btnsealbag, button btncashok, label labelpaid, label labelsealbag, label labeltopay, label lblexchange, label labelexchange, label labelreturnamount, int amount, node node, payscreen parent, sealbagtextfield sealbagtextfield) {     int paid = 0;     logger.debug("cashpopup on gui thread: " + platform.isfxapplicationthread());     platform.runlater(new runnable() {         @override         public void run() {             cashpopup.getcontent().clear();             rectangle rectangle = new rectangle();             rectangle.setarcheight(20);             rectangle.setarcwidth(20);             rectangle.setfill(color.lightblue);             rectangle.setwidth(466);             rectangle.setheight(311);             rectangle.setstroke(color.darkblue);             rectangle.setstroketype(stroketype.inside);              ...               cashpopup.getcontent().addall(rectangle, textarea, headerlabel, lbldesc, lblamount, labelamount, lblpaid, labelpaid, lbltopay, labeltopay, btncashok, lblsealbag, labelsealbag, lblexchange, labelexchange, labelreturnamount, btnsealbag, btncancel);              cashpopup.show(node, 150, 164);         }     });     return paid; } 

and showmessagepopup:

public static void showmessagepopup(string title, string text, string buttontext, int posx, int posy, node parent) {     logger.debug("messagepopup on gui thread: " + platform.isfxapplicationthread());     platform.runlater(new runnable() {         @override         public void run() {             logger.debug("0");             messagepopup.getcontent().clear();             rectangle rectangle = new rectangle();             rectangle.setarcheight(20);             rectangle.setarcwidth(20);             rectangle.setfill(color.lightblue);             rectangle.setwidth(500);             rectangle.setheight(300);             rectangle.setstroke(color.darkblue);             rectangle.setstroketype(stroketype.inside);             label headerlabel = new label(title);             headerlabel.setstyle("-fx-font-size: 18; -fx-font-family: arial;");             headerlabel.setlayoutx(15);             headerlabel.setlayouty(10);             textarea textarea = new textarea();             textarea.setstyle("-fx-font-size: 14; -fx-font-family: arial;");             textarea.setlayoutx(10);             textarea.setlayouty(35);             textarea.setmaxwidth(480);             textarea.setminheight(190);             textarea.setmaxheight(190);             textarea.seteditable(false);             textarea.setwraptext(true);             textarea.settext(text);              button btnclose =  new button(buttontext);             btnclose.setlayoutx(180);             btnclose.setlayouty(235);             btnclose.setprefsize(120, 54);             btnclose.setstyle("-fx-font-size: 18; -fx-font-family: arial; -fx-text-fill:white; -fx-background-color: linear-gradient(#8b9aa1, #456e84), linear-gradient(#c5dde7, #639fba), linear-gradient(#79abc1, #639fba); -fx-background-insets: 0,1,2; -fx-background-radius: 6,5,4;");             btnclose.setonaction(new eventhandler<actionevent>() {                 @override                 public void handle(actionevent event) {                     messagepopup.hide();                 }             });             messagepopup.getcontent().addall(rectangle, headerlabel, btnclose, textarea);             messagepopup.show(parent, posx, posy);         }     }); } 

logger.debug("0") isn't executed ...

found it, running in debug mode , suspending java fx thread see doing. there's 'other thread' gets started main program , needs started before process can continue. other thread looks this:

    pinpadasslavethread = new thread(pinpadasslave);     pinpadasslavethread.start();     while (!pinpadasslave.isrunning()) {         // wait pinpadasslave running         try {             thread.sleep(10);         } catch(interruptedexception ie) {             // ignore         }     } 

normally takes 50 ms, pin pad unavailable on network becomes infinite loop. on should handled of course, letting loop try 50 times or so. real problem thread put sleep 10 ms time java fx thread. don't know why java fx thread doing setting of communication, shouldn't (and didn't ask putting inside platform.runlater or alike), fact is: ...


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -