Hi,
I have the following use case:
I have a Control with a Skin. The Skin is a Hbox and contains a TextField.
The control has a CSS class "myControl".
If I want to select only the TextField which is part of the control I can do that with:
.myControl .text-field {}
Now I want to set an invalid state to the control, so I add a CSS class "invalid".
How can I now select the text field, because I want to mark only the text field (no other parts of the control) as invalid?
I tried it with:
.myControl .invalid .text-field
but it doesn't work.
It should work kind of as a pseudo-class.
Here is just a slight different sample.
I want that all text fields, which are within a VBox (or other control) that has BOTH classes "myControl" and "invalid" to have blue background.
.myHBox .invalid .text-field {
-fx-background-color: blue;
}
doesn't work.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp5 extends Application {
public static void main(String[] args) throws Exception {
launch();
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox(5);
VBox vBox = new VBox(5);
vBox.getStyleClass().add("myControl");
vBox.getChildren().add(new TextField());
vBox.getChildren().add(new TextField());
vBox.getChildren().add(new TextField());
root.getChildren().add(vBox);
vBox.getStyleClass().add("invalid");
TextField unstyledTextField = new TextField();
root.getChildren().add(unstyledTextField);
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles.css");
stage.setScene(scene);
stage.show();
}
}