2012-11-18 38 views
3

我想JavaFX中使用一種叫做樣式表的背景圖像添加到我的AnchorPaneStyle.cssCSS錯誤

當我運行該程序,我得到以下警告:

警告: com.sun.javafx.css.parser.CSSParser聲明CSS錯誤 解析內嵌樣式從[email protected] '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; 
     } 

誰能告訴我什麼是錯的代碼?

回答

5

在您的代碼在行

// setting the anchorPanes ID to AnchorPane 
chat.setStyle("AnchorPane"); 

你設置樣式不ID。它應該是

chat.setId("AnchorPane"); 

有關更多詳細信息,請參見Skinning JavaFX Applications with CSS