javafx doesnt repaint label till method has finished, why?

Posted by jeff porter on Stack Overflow See other posts from Stack Overflow or by jeff porter
Published on 2010-05-05T20:22:50Z Indexed on 2010/05/05 20:28 UTC
Read the original article Hit count: 438

Filed under:

Hi all,

I have a JavaFX app with a some code like this...

public class MainListener extends EventListener{
    override public function event (arg0 : String) : Void {
     statusText.content = arg0;
    }
}

statusText is defined like this...

    var statusText = Text {
    x: 30
    y: stageHeight - 40
    font: Font { name: "Bitstream Vera Sans Bold" size: 10 }
    wrappingWidth: 420
    fill: Color.WHITE
    textAlignment: TextAlignment.CENTER
    content: "Status: awaiting DBF file."
};

I also have some other Javacode that is load data, much like this..

public ArrayList<CustomerRecord> read(EventListener listener) {

    ArrayList<CustomerRecord> listOfCustomerRecords = new ArrayList<CustomerRecord>();
        listener.event("Status: Starting read");

        // ** takes a while...
        List<Map<String, CustomerField>> customerRecords = new Reader(file).readData(listener);
        // ** long running method over.

        listener.event("Status: Loaded all customers, count:" + listOfCustomerRecords.size());
    return listOfCustomerRecords;
}

Now while the last method is in its long running call, I would expect to see my statusText updated to have 'Status: Starting read', but its doesn't. Its only when the read() method returns that the text is updated.

If its was 'straight' java I would presume that the long running job is hogging the CPU, or the statusText needed to have repaint() called on it.

Can anyone give me any ideas?

Thanks Jeff Porter

© Stack Overflow or respective owner

Related posts about javafx