我正在尝试使用ImageView预览不同的图像(取决于文件名),但出于某种原因,它会加载图像而不进行预览。
public void imageRec(){ //method called upon when the file is changed
String imfichier = resources[track].getName(); //gets the name of the current song
String imName = imfichier.substring(0, imfichier.lastIndexOf(".")); //removes the ".mp3" extension from the current song
File ff = new File("cover/" + imName + ".png"); //loads the image
image = new Image(ff.toURI().toString());
cover.setImage(image); //Should preview the image but nothing happens
cover.setCache(true); //cover is the fx:id of ImageView
}
我知道我可以直接在 .fxml 文件中加载网址,但如果我这样做,我将无法更改图像。有什么建议?