1
我有一個由幾個Label控件組成的自定義控件:日期,標題,文本等。控件有fxml文件和控制器。我想用這個控件作爲ListView的一個單元格。我創建了一個自定義的ListCell在JavaFx 8 listview單元格中的自定義控件fxml
public class NoteTextCell extends ListCell<Note>{
//....
protected void updateItem(Note note, boolean isEmpty){
if(isEmpty|| note == null){
//....
}
else {
FXMLLoader loader = new FXMLLoader(getClass().getResource("fxml/note.fxml"));
Node node = loader.load();
setGraphic(node);
}
}
}
但我不知道它是做正確的方式。我的應用程序中的ListView可能有成千上萬的項目。在我對每個單元更新的理解中,它必須在創建圖形節點之前加載fxml,進行解析和其他操作。有沒有更好的方法來解決這個問題?