2012-05-30 165 views
0
String image = JavaFXApplication9.class.getResource("splash.jpg").toExternalForm(); 
     root.setStyle(" -fx-background-image: url('" + image + "'); 
       -fx-background-position: center center; 
       -fx-background-repeat: stretch;"); 

任何人都可以幫我解決這個問題嗎? :S我嘗試了很多。背景圖片不能正常工作

我知道這是一個小錯誤。

回答

0

嘗試清理並重新構建該項目。根據本實現一個
編輯你的啓動方法:
編輯

@Override 
public void start(Stage primaryStage) { 
    StackPane root = new StackPane(); 
    String image = this.getClass().getResource("splash.jpg").toExternalForm(); 
    root.setStyle(" -fx-background-image: url('" + image + "'); " 
      + "-fx-background-position: center center; " 
      + "-fx-background-repeat: stretch;"); 
    primaryStage.setScene(new Scene(root, 300, 250)); 
    primaryStage.show(); 
} 

要確保splash.jpg圖像文件是在同一個包你的主類。

+0

嗯沒有其他解決方案? – IlhamiD

+0

編碼'System.out.println(「path:」+ image);'並檢查圖像是否存在於該路徑。 –

+0

它給我一個語法錯誤。 :( – IlhamiD