What is the difference between javafx.scene.text.Text and javafx.scene.control.Label?
javafx.scene.text.Text和javafx.scene.control.Label有什么区别?
The documentation says:
文件说:
- Label is a non-editable text control.
- Label是一个不可编辑的文本控件。
- The Text class defines a node that displays a text.
- Text类定义显示文本的节点。
But the Label class has a method "setText" and "textProperty", therefore is editable.
但Label类有一个方法“setText”和“textProperty”,因此是可编辑的。
2 个解决方案
#1
66
As Harry Blargle pointed out, "non-editable" means "not editable by the user." So both Label and Text are non-editable.
正如Harry Blargle指出的那样,“不可编辑”意味着“不能被用户编辑”。因此Label和Text都是不可编辑的。
Label and Text have different CSS properties. Label inherits from Labeled, Control, and Region, which means it inherits a great many styleable properties which Text doesn't have. A Label can have alignment, a graphic, a background, a border, a displayed keyboard mnemonic, built-in wrapping, and can be intelligently clipped with an ellipsis ("…").
标签和文本具有不同的CSS属性。 Label继承自Labeled,Control和Region,这意味着它继承了Text没有的许多可定制属性。标签可以具有对齐,图形,背景,边框,显示的键盘助记符,内置包装,并且可以使用省略号(“...”)智能地剪裁。
Text can participate in a TextFlow. (Technically, Label can also, but it is treated as just another embedded control and is not laid out as text.)
文本可以参与TextFlow。 (从技术上讲,Label也可以,但它被视为另一个嵌入式控件,并不作为文本布局。)
In general, if you want to show the purpose of an input control by placing one or more words next to it, and/or you want to allow direct keyboard navigation to an input control, you use a Label. If you want to display text content not associated with input, you use Text.
通常,如果要通过在其旁边放置一个或多个单词来显示输入控件的用途,和/或您希望允许直接键盘导航到输入控件,则使用Label。如果要显示与输入无关的文本内容,请使用“文本”。
#2
12
A Text
is a geometric shape (like a Rectangle or a Circle), while Label
is a UI control (like a Button or a CheckBox).
Text是几何形状(如Rectangle或Circle),而Label是UI控件(如Button或CheckBox)。
In Swing, geometric shapes were restricted to the painting mechanism, while in JavaFX they can be used in more generic ways.
在Swing中,几何形状仅限于绘制机制,而在JavaFX中,它们可以以更通用的方式使用。
#1
66
As Harry Blargle pointed out, "non-editable" means "not editable by the user." So both Label and Text are non-editable.
正如Harry Blargle指出的那样,“不可编辑”意味着“不能被用户编辑”。因此Label和Text都是不可编辑的。
Label and Text have different CSS properties. Label inherits from Labeled, Control, and Region, which means it inherits a great many styleable properties which Text doesn't have. A Label can have alignment, a graphic, a background, a border, a displayed keyboard mnemonic, built-in wrapping, and can be intelligently clipped with an ellipsis ("…").
标签和文本具有不同的CSS属性。 Label继承自Labeled,Control和Region,这意味着它继承了Text没有的许多可定制属性。标签可以具有对齐,图形,背景,边框,显示的键盘助记符,内置包装,并且可以使用省略号(“...”)智能地剪裁。
Text can participate in a TextFlow. (Technically, Label can also, but it is treated as just another embedded control and is not laid out as text.)
文本可以参与TextFlow。 (从技术上讲,Label也可以,但它被视为另一个嵌入式控件,并不作为文本布局。)
In general, if you want to show the purpose of an input control by placing one or more words next to it, and/or you want to allow direct keyboard navigation to an input control, you use a Label. If you want to display text content not associated with input, you use Text.
通常,如果要通过在其旁边放置一个或多个单词来显示输入控件的用途,和/或您希望允许直接键盘导航到输入控件,则使用Label。如果要显示与输入无关的文本内容,请使用“文本”。
#2
12
A Text
is a geometric shape (like a Rectangle or a Circle), while Label
is a UI control (like a Button or a CheckBox).
Text是几何形状(如Rectangle或Circle),而Label是UI控件(如Button或CheckBox)。
In Swing, geometric shapes were restricted to the painting mechanism, while in JavaFX they can be used in more generic ways.
在Swing中,几何形状仅限于绘制机制,而在JavaFX中,它们可以以更通用的方式使用。