CSS error in JavaFX project

css, java, javafx

Solution

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.

Problem

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?

Original source