JavaFX中的Node.setDisable()vs setDisabled() [英] Node.setDisable() vs setDisabled() in JavaFX

查看:1111
本文介绍了JavaFX中的Node.setDisable()vs setDisabled()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继承自 javafx.scene.Node 时,有两种方法可供调用:(我正在展示当前的8u66 Oracle实现)

There are two methods available for calling when inheriting from javafx.scene.Node: (I am showing off the current 8u66 Oracle implementation)

setDisable(boolean)

public final void setDisable(boolean value) {
    disableProperty().set(value);
}

setDisabled(boolean)

protected final void setDisabled(boolean value) {
    disabledPropertyImpl().set(value);
}

javafx继承时,我应该调用哪一个。 scene.Node

推荐答案

这取决于上下文,但你几乎肯定想要调用 setDisable(...)

It depends a bit on the context, but you almost certainly want to call setDisable(...).

在JavaFX中,节点呈现为已禁用,如果禁用属性为<,则忽略任何用户输入code> true ,或者如果禁用属性为场景图中的任何祖先,则为 已禁用属性(该节点的客户端的只读属性)反映了此整体状态:即已禁用当且仅当 disable 对于此节点或其任何祖先(容器)节点为真时才为真。

In JavaFX, a node is rendered as disabled, and ignores any user input, if its disable property is true, or if the disable property is true for any ancestor in the scene graph. The disabled property, which is a read-only property for clients of the node, reflects this overall state: i.e. disabled is true if and only if disable is true for this node or for any of its ancestor (container) nodes.

因此,要禁用节点,通常应调用 setDisable(true); 。在 Node 的自定义子类中,您应该只调用 setDisabled(true); 来强制执行上述规则。请注意,超类实现已经强制执行此规则,因此,除非您执行的操作非常复杂(我甚至不能真正看到用例),否则您无需调用 setDisabled(...)

So to disable a node, you should typically call setDisable(true);. In a custom subclass of Node, you should only call setDisabled(true); to enforce the rule described above. Note that the superclass implementation will already enforce this rule, so unless you are doing something very complex (I can't even really see a use case), you will not need to call setDisabled(...).

这篇关于JavaFX中的Node.setDisable()vs setDisabled()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆