3

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.