JavaFX 通过 css 设置标签文本

JavaFX set label text by css

我想知道是否可以通过 javafx-css 设置标签文本。 在官方文档中,我找到了对

的引用
-fx-text: "whatever";

但没有用,基本上我正在搜索 css3

的等价物
content: "whatever";

此处指定:W3School

这在 JavaFX 中是不可能的,您可以通过从 Label:

获取所有可设置样式的属性来轻松验证这一点
Label label = new Label();
label.getCssMetaData().stream().map(CssMetaData::getProperty).sorted().forEach(System.out::println);

生成以下列表(不包括 -fx-text 或任何允许您根据 CSS Reference Guide 设置内容的内容):

-fx-alignment
-fx-blend-mode
-fx-content-display
-fx-cursor
-fx-effect
-fx-ellipsis-string
-fx-focus-traversable
-fx-font
-fx-graphic
-fx-graphic-text-gap
-fx-label-padding
-fx-line-spacing
-fx-max-height
-fx-max-width
-fx-min-height
-fx-min-width
-fx-opacity
-fx-opaque-insets
-fx-padding
-fx-position-shape
-fx-pref-height
-fx-pref-width
-fx-region-background
-fx-region-border
-fx-rotate
-fx-scale-shape
-fx-scale-x
-fx-scale-y
-fx-scale-z
-fx-shape
-fx-skin
-fx-snap-to-pixel
-fx-text-alignment
-fx-text-fill
-fx-text-overrun
-fx-translate-x
-fx-translate-y
-fx-translate-z
-fx-underline
-fx-wrap-text
visibility