0

I have exams soon and my teacher just can't explain it. I've already read https://docs.oracle.com/javafx/2/api/javafx/beans/value/ObservableValue.html and don't understand the InvalidationListener. At what time is the ObservableValue recomputed so the InvalidationsListeners method invalidated would be executed? In which cases would the Listeners method run if I would use an ChangeListener but not if I would use an InvalidationListener?

  • 1
    take a look at this answer https://stackoverflow.com/a/45117265/12199915 – Alex Jun 28 '20 at 10:44
  • This distinction is described in the javadoc you've linked to. What part of that are you having trouble understanding. – matt Jun 28 '20 at 10:48
  • I don't understand at what time a value that is seen as invalid is valid again. I do understand that if I access the value in an InvalidationListener I can just use a ChangeListener. But if I don't access the value when is the method invalidated executed and what's the difference to a ChangeListener – voidNote Jun 28 '20 at 10:57
  • The example that's given here is when you add a Listener to a value that's computed out of two others. I do understand that the value is only valid again if you access it. But what about other properties like textProperty. At what time do they count as invalidated but are not accessed again so they become valid? – voidNote Jun 28 '20 at 11:05
  • A `text` property would become invalid when its value has potentially changed. It becomes valid again as soon as its value is queried. If a `ChangeListener` is registered then the property will become valid immediately after becoming invalid due to the nature of `ChangeListener`; the listener requires the old and _new_ values, which means the new value must be computed eagerly. – Slaw Jun 28 '20 at 11:18

0 Answers0