我開始製作使用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;
}
我試了這個,仍然有同樣的問題 –