Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with CSS and nested node hierarchy

cshJun 29 2012 — edited Jun 29 2012
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();
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2012
Added on Jun 29 2012
1 comment
198 views