In JavaFX, is binding an alternative to action-lis

2019-07-10 03:50发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-07-10 04:18

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.

查看更多
登录 后发表回答