JavaFX14/Listener not called

Nir Lisker nlisker at gmail.com
Thu Aug 20 14:57:19 UTC 2020


Hi Peter,

This is a development mailing list, not a help list. I suggest you ask
questions on a help site.

The reason you see this difference is that you're using an invalidation
listener which uses lazy evaluation, so in your second example it is not
updated because it is not used in the printing method. Read the
documentations/tutorial of listeners and observables.

- Nir

On Thu, Aug 20, 2020 at 5:19 PM Petr Nemecek <pnem at cmail.cz> wrote:

> 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