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,进行解析和其他操作。有没有更好的方法来解决这个问题?