在JavaFX中,绑定是动作侦听器的替代方法吗? [英] In JavaFX, is binding an alternative to action-listener?
问题描述
我想知道在JavaFX中绑定是否可以替代动作侦听器/事件? 我们可以用绑定而不是事件处理来处理所有动作吗?
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 ?
推荐答案
否,事件处理程序.
您可以将事件属性绑定到不同的事件处理程序,但是随后您将同时使用这两种技术,而不是其中一种.
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.
这篇关于在JavaFX中,绑定是动作侦听器的替代方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!