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");
有关更多详细信息,请参阅