1
有沒有可能在文本旁邊的ListView中有圖像?圖像具有相同的名稱,如「oddelenyObsah []」。這應該像清單一樣工作,在列表視圖中是庫存中的物品,我需要旁邊的物品圖片。ListView與圖像JavaFX
private HerniPlan plan;
private Batoh batoh;
ListView<String> list;
ObservableList<String> data;
private final Image boty = new Image("../zdroje/boty.png");
private final Image odpadky = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image varecka = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image panev = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image desky = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image nuzky = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image pacidlo = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image rezavy_klic = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private final Image klic_od_domu = new Image("https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo_64x64.png");
private Image[] listOfImages = {boty, odpadky, varecka, panev, desky, nuzky, pacidlo, rezavy_klic, klic_od_domu};
public PanelBatohu(Batoh batoh) {
this.batoh = batoh;
batoh.zaregistrujPozorovateleBatohu(this);
init();
}
private void init() {
list = new ListView<>();
data = FXCollections.observableArrayList();
list.setItems(data);
list.setPrefWidth(200);
aktualizujBatoh();
}
public ListView<String> getList() {
return list;
}
@Override
public void aktualizujBatoh() {
String veci = batoh.seznamVBatohu();
data.clear();
String[] oddelenyObsah = veci.split(" ");
for (int i = 1; i < oddelenyObsah.length; i++) {
if(veci.equals(boty)){
}
data.add(oddelenyObsah[i]);
}
}
/**
* Metoda zaregistruje pozorovatele k hernímu plánu při spuštění nové hry.
*
* @param batoh
*/
public void nastaveniHernihoPlanu(Batoh batoh) {
this.batoh = batoh;
batoh.zaregistrujPozorovateleBatohu(this);
this.aktualizujBatoh();
}
}
能不能請你把它declarete到我的代碼?我幾次看過這個解決方案,但我不知道如何使用它,因爲我很笨,對不起隊友。 – dzb