Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.javafx.runtime.VersionInfo;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.ListCell;
- import javafx.scene.control.ListView;
- import javafx.stage.Stage;
- import javafx.util.Callback;
- public class SlowInitCell extends Application {
- @Override
- public void start(Stage stage) throws Exception {
- ListView<String> listView = new ListView<>();
- listView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
- @Override
- public ListCell<String> call(ListView<String> stringListView) {
- return new CustomListCell();
- }
- });
- for(int i=0;i<10000;i++) {
- listView.getItems().add("List item " + i);
- }
- stage.setTitle("List View Scrolling");
- stage.setScene(new Scene(listView));
- stage.show();
- }
- public static void main(String[] args) {
- System.out.println(VersionInfo.getRuntimeVersion());
- launch(args);
- }
- private class CustomListCell extends ListCell<String> {
- private final Label label = new Label();
- private CustomListCell() {
- try {
- Thread.sleep(50);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- protected void updateItem(String s, boolean empty) {
- super.updateItem(s, empty);
- if(!empty) {
- label.setText(s);
- setGraphic(label);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement