The behaviour of adding a style class via a LabelBuilder.styleClass("<class>"). and via the Label's getStyleClass().add("<class>") methods differ.
When the style class is set on the Label, it is not required to set a -fx-skin style property.
When the style class is set on the LabelBuilder, if a -fx-skin style is not set to "com.sun.javafx.scene.control.skin.LabelSkin", the label does not display and the following line is shown repeatedly in System.out.
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Label@48f50903[styleClass=twentyzeroone]
--------------------------
Workaround exists to set -fx-skin: "com.sun.javafx.scene.control.skin.LabelSkin"; in the control's css (or just not use the LabelBuilder to set the styleclass), but this is kind of non-intuitive and the -fx-skin stuff doesn't seem to be documented anywhere anyway.
--------------------------
Example files for a minimal test case are attached.
File: server.css
===========
.twentyzeroone {
-fx-font-weight: bold;
/*-fx-skin: "com.sun.javafx.scene.control.skin.LabelSkin";*/
}
-----------------------------
File: CSSSevere.java
===============
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.LabelBuilder;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CSSSevere extends Application {
public static void main(String[] args) { Application.launch(args); }
String requestString = "Open the pod bay doors, HAL.";
String failureString = "I'm sorry, Dave. I'm afraid I can't do that.";
@Override public void start(Stage primaryStage) {
VBox root = new VBox();
Label okLabel = new Label(requestString);
okLabel.getStyleClass().add("twentyzeroone");
root.getChildren().add(okLabel);
Label severeLabel = LabelBuilder.create().text(failureString).styleClass("twentyzeroone").build();
root.getChildren().add(severeLabel);
Scene scene = new Scene(root, 300, 250);
scene.getStylesheets().add("severe.css");
primaryStage.setScene(scene);
primaryStage.show();
}
}
When the style class is set on the Label, it is not required to set a -fx-skin style property.
When the style class is set on the LabelBuilder, if a -fx-skin style is not set to "com.sun.javafx.scene.control.skin.LabelSkin", the label does not display and the following line is shown repeatedly in System.out.
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for Label@48f50903[styleClass=twentyzeroone]
--------------------------
Workaround exists to set -fx-skin: "com.sun.javafx.scene.control.skin.LabelSkin"; in the control's css (or just not use the LabelBuilder to set the styleclass), but this is kind of non-intuitive and the -fx-skin stuff doesn't seem to be documented anywhere anyway.
--------------------------
Example files for a minimal test case are attached.
File: server.css
===========
.twentyzeroone {
-fx-font-weight: bold;
/*-fx-skin: "com.sun.javafx.scene.control.skin.LabelSkin";*/
}
-----------------------------
File: CSSSevere.java
===============
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.LabelBuilder;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CSSSevere extends Application {
public static void main(String[] args) { Application.launch(args); }
String requestString = "Open the pod bay doors, HAL.";
String failureString = "I'm sorry, Dave. I'm afraid I can't do that.";
@Override public void start(Stage primaryStage) {
VBox root = new VBox();
Label okLabel = new Label(requestString);
okLabel.getStyleClass().add("twentyzeroone");
root.getChildren().add(okLabel);
Label severeLabel = LabelBuilder.create().text(failureString).styleClass("twentyzeroone").build();
root.getChildren().add(severeLabel);
Scene scene = new Scene(root, 300, 250);
scene.getStylesheets().add("severe.css");
primaryStage.setScene(scene);
primaryStage.show();
}
}
- duplicates
-
JDK-8101528 Problems creating scene graph with Builders
-
- Closed
-