我正在尝试AnchorPane
使用名为的样式表在 JavaFX中添加背景图像Style.css
当我运行程序时,我收到以下警告:
警告:com.sun.javafx.css.parser.CSSParser 声明 CSS 解析来自 javafx.scene.Node$22@5c4a9e8e 的内联样式“AnchorPane”时出错:预期冒号位于 [-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');
}
我的 Java 代码如下所示:
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;
}
谁能告诉我这段代码有什么问题?