CSS error in JavaFX project


Question

I'm trying to add a background image to my AnchorPane in JavaFX using a stylesheet called Style.css

When I run the program I get the following warning:

WARNING: com.sun.javafx.css.parser.CSSParser declaration CSS Error parsing in-line style 'AnchorPane' from javafx.scene.Node$22@5c4a9e8e: Expected COLON at [-1,-1]

My CSS file looks like this:

#AnchorPane{
    -fx-background-image:url('penthouse.png');
    -fx-background-repeat: no-repeat;
}

.chat{
    -fx-background-image:url('penthouse.png');
    -fx-background-repeat: no-repeat;
}
#btnSend{

}
#txtMessage{

}
#Figur{
    -fx-background-image:url('Figur.png');
}

My Java code looks like this:

    public void start(Stage primaryStage) throws Exception {

            BorderPane bp = new BorderPane();

            bp.setRight(createRightOptionPane());
            bp.setBottom(createMessagePane());
            bp.setCenter(createVisualChat());
            Group root = new Group();
            root.getChildren().add(bp);
            Scene scene = new Scene(root);

 // adding the stylesheet to the scene
            scene.getStylesheets().add("Style.css"); 


            primaryStage.setScene(scene);
            primaryStage.setWidth(478);

            primaryStage.setHeight(433);
            primaryStage.setTitle("Chat");
            primaryStage.show();

        }

        private Node createVisualChat() {
            AnchorPane chat = new AnchorPane();
            // setting the anchorPanes ID to AnchorPane
       chat.setStyle("AnchorPane");


            return chat;
        }

Can anyone tell me what is wrong with this code?

1
3
7/3/2016 10:08:16 PM

Accepted Answer

In your code at line

// setting the anchorPanes ID to AnchorPane
chat.setStyle("AnchorPane");

you are setting the style not ID. It should be

chat.setId("AnchorPane");

See Skinning JavaFX Applications with CSS for more details.

5
11/18/2012 7:10:47 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon