[英]Why does TextField inherit from javafx.scene.Parent in JavaFX?
I am reading javafx TextField API: 我正在阅读javafx TextField API:
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
javafx.scene.control.TextInputControl
javafx.scene.control.TextField
As you see, TextField inherits from javafx.scene.Parent class. 如您所见,TextField继承自javafx.scene.Parent类。 From Parent class javadoc
The base class for all nodes that have children in the scene graph.
From Parent class javadoc
The base class for all nodes that have children in the scene graph.
But I can't understand what child nodes TextField can have. 但是我不明白TextField可以拥有哪些子节点。 Can anyone explain?
谁能解释?
This is because a TextField
is not made up of a single Node
. 这是因为
TextField
不是由单个Node
。 For instance, it uses (different) Text
nodes for the prompt and normal text. 例如,它对提示文本和普通文本使用(不同的)“
Text
节点。 It also uses a Path
for the caret. 它还为插入符使用
Path
。 For Control
s, this is implemented using a Skin
(eg TextInputControlSkin
and TextFieldSkin
). 对于
Control
,这是使用Skin
(例如TextInputControlSkin
和TextFieldSkin
)实现的。
Notice, however, that TextField
doesn't expose its children publicly for modification; 但是请注意,
TextField
不会公开公开其子级以进行修改; random code can't just go adding nodes to it. 随机代码不能随便添加节点。 But you can view the children in an unmodifiable fashion.
但是您可以以不可修改的方式查看孩子。
It can have any child node you want it to - there's no inherent reason why you couldn't add something like a label, a graphic, or a weird shape as its child. 它可以具有您想要的任何子节点-没有固有的原因为什么您不能为其子项添加标签,图形或怪异的形状。 Try it out - it works!
试试看-它有效!
In practice you probably wouldn't do this, you'd add both the textfield and the weird shape (or whatever else) to a StackPane or similar instead, as that gives you greater control over layout and extensibility. 实际上,您可能不会这样做,而是将文本字段和怪异的形状(或其他任何形状)添加到StackPane或类似对象中,因为这样可以更好地控制布局和可扩展性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.