JavaFX 中的标签和文本差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24374867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:51:03  来源:igfitidea点击:

Label and Text differences in JavaFX

javajavafxfxml

提问by multiplayer1080

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.
  • 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”,因此是可编辑的。

采纳答案by VGR

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.)

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.

通常,如果您想通过在输入控件旁边放置一个或多个单词来显示其用途,和/或您希望允许直接通过键盘导航到输入控件,则可以使用标签。如果要显示与输入无关的文本内容,请使用 Text。

回答by Jan Bodnar

A Textis a geometric shape (like a Rectangle or a Circle), while Labelis a UI control (like a Button or a CheckBox).

AText是几何形状(如矩形或圆形), Label而是 UI 控件(如按钮或复选框)。

In Swing, geometric shapes were restricted to the painting mechanism, while in JavaFX they can be used in more generic ways.

在 Swing 中,几何形状仅限于绘制机制,而在 JavaFX 中,它们可以以更通用的方式使用。

回答by Vaibhav Agarwal

Labels

标签

  • A label displays text or image which the user cannot directly change or edit . *specify the image for the label.
  • 标签显示用户无法直接更改或编辑的文本或图像。*指定标签的图像。

TextFields

文本字段

  • A TextField displays text or image which the user can directly change or edit ..
  • don't specify image for the text field
  • TextField 显示用户可以直接更改或编辑的文本或图像。
  • 不要为文本字段指定图像