Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX项目中的CSS错误_Java_Css_Javafx - Fatal编程技术网

JavaFX项目中的CSS错误

JavaFX项目中的CSS错误,java,css,javafx,Java,Css,Javafx,我试图使用名为Style.css的样式表在JavaFX中为我的AnchorPane添加背景图像 当我运行程序时,我收到以下警告: 警告:com.sun.javafx.css.parser.CSSParser声明css错误 从javafx.scene.Node解析内嵌样式“AnchorPane”$22@5c4a9e8e: 在[-1,-1]处应为冒号 我的CSS文件如下所示: #AnchorPane{ -fx-background-image:url('penthouse.png');

我试图使用名为
Style.css的样式表在JavaFX中为我的
AnchorPane
添加背景图像

当我运行程序时,我收到以下警告:

警告:com.sun.javafx.css.parser.CSSParser声明css错误 从javafx.scene.Node解析内嵌样式“AnchorPane”$22@5c4a9e8e: 在[-1,-1]处应为冒号

我的CSS文件如下所示:

#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');
}
    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;
        }
我的Java代码如下所示:

#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');
}
    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;
        }
有人能告诉我这个代码有什么问题吗?

在代码的第行

// setting the anchorPanes ID to AnchorPane
chat.setStyle("AnchorPane");
您正在设置的样式不是ID。它应该是

chat.setId("AnchorPane");
有关更多详细信息,请参阅