2016-07-10 37 views
0

我開始製作使用javafx和CSS文件進行樣式的小程序當我從netbeans運行程序時改變背景,但是當我從jar文件運行它時在「DIST」文件夾中創建的NetBeans背景消失了,請我需要的代碼CSS樣式不能在導出的javafx可運行jar中工作

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package finalfx; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.image.Image; 
import javafx.stage.Stage; 

/** 
* 
*/ 
public class FinalFX extends Application { 

    @Override 
    public void start(Stage stage) throws Exception { 
     Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); 

     Scene scene = new Scene(root); 
     scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm()); 
      stage.getIcons().add(new Image("patient-icon-8.ico")); 


     stage.setScene(scene); 
     stage.show(); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 
} 

低於你的幫助

//////////////////// //////

CSS代碼

.root { 
    -fx-background-image: url("84770f_6b54c02021f64aa38d05264a9afc3f80[1].jpg"); 

    -fx-background-repeat: stretch; 
    -fx-background-size: 1904 1001; 
    -fx-background-position: center; 

} 
+0

我試了這個,仍然有同樣的問題 –

回答

0

與您的本地.jpg文件相比,您的css文件在哪裏?

../向你提出了CSS是夾在

../images/進入images文件夾

-fx背景圖像:網址(」 。 ./images/84770f_6b54c02021f64aa38d05264a9afc3f80[1].jpg「);

+0

在同一個文件夾 –

+0

你建議分開文件夾 –

+0

這是一個假設,如果它沒有看到它們在不同的文件夾中的圖像。然而,將文件分類到文件夾可能會讓您的生活更輕鬆。 –

相關問題