I was wondering if in JavaFX, binding can be an alternative to action listener/events ? Can we handle all actions with binding instead of event handling ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
No, binding is not an alternative to event handlers.
You could bind event properties to different event handlers, but then you would be using both technologies, not one or the other.
Generally you use binding for synchronizing data values and event handlers for running code on some event.
As an alternative to a bind call to set the value of dependent property, you can use change listeners to react on a change and trigger arbitrary code which could set the value of a dependent property. A change listener is different from an event handler. Change listeners and invalidation listeners can be used as an alternative to a binding but not vice versa in a general case.