VirtualFlow
本地的,另一个是来自无流库的实现。我知道如何使用无流量
JavaFX
,但是现在,我想尝试使用javafx
VirtuaFlow
。但是,我不明白如何将
VirtualFlow
项目传递给此。这是我的代码:
ObservableList<T>
有人会说怎么做吗?
VirtualFlow
public class NewMain extends Application {
public class VirtualCell<T> extends IndexedCell<T> {
}
private final VirtualFlow<VirtualCell<String>> virtualFlow = new VirtualFlow<>();
@Override
public void start(Stage primaryStage) {
this.virtualFlow.setCellFactory(v -> new VirtualCell<>());
List<String> list = new ArrayList<>();
for (var i = 0; i < 100; i++) {
list.add("Item " + i);
}
ObservableList<String> items = FXCollections.observableArrayList(list);
//this.virtualFlow.set items ????
var root = new VBox(this.virtualFlow);
Scene scene = new Scene(root, 600, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
。
您应该扩展
VirtualFlow
以直接处理字符串。
ObservableList
ListCell<>
类扩展public class VirtCell<T> extends IndexedCell<T> {
@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.toString());
}
}
}
并覆盖了正确显示项目的方法。然后您需要设置小区工厂:
VirtCell
使用
IndexedCell
和
updateItem
。