JavaFX14/Listener not called

Petr Nemecek pnem at cmail.cz
Thu Aug 20 14:16:41 UTC 2020


Dear all,

 

could somebody explain me, please, why the output differs for CODE-1 and
CODE-2 see below? I would expect the listener to be called four times in
both cases.

 

I believe there's trivial answer for that, but I'm not able to find it by
myself, probably due to the hot weather here in Prague, CZ.

 

Many thanks,

Petr

 

***

CODE-1

IntegerProperty property = new SimpleIntegerProperty();

        

property.addListener((o) -> {

        System.out.println("value changed to " + property.get() + " ... " +
System.currentTimeMillis());                    

});

        

for (int i = 0; i < 5; i++) {

    property.set(i);

}

 

OUTPUT-1

value changed to 1 ... 1597932211288

value changed to 2 ... 1597932211293

value changed to 3 ... 1597932211293

value changed to 4 ... 1597932211294

 

***

CODE-2

IntegerProperty property = new SimpleIntegerProperty();

        

property.addListener((o) -> {

   System.out.println("value changed" + " . " + System.currentTimeMillis());

});

        

for (int i = 0; i < 5; i++) {

     property.set(i);

}

 

OUTPUT-2

value changed ... 1597932237151

***



More information about the openjfx-dev mailing list