0

Trying to display images in a thumbnail form to listview in a gridpane

 ObservableList<File> imageFiles = FXCollections.observableArrayList();
 List<File> list = fileChooser.showOpenMultipleDialog(null);

    if(list != null){
        for(File file : list){
            //Image image = new Image(file.toURI().toString());
            final Image image = new Image(new FileInputStream(file), 150, 150, true, false);
            ImageView imageView = new ImageView();
            imageView = createImageView(image);

            if(check1.isSelected()){


                VBox vl = new VBox();
                vl.getChildren().addAll(imageView);

                ListView<File> imageFilesList = new ListView<>(imageFiles);
                imageFilesList.setCellFactory(listview -> new ListCell<File>(){
                    private final ImageView imageView = new ImageView();
                    {
                        imageView.setFitHeight(80);
                        imageView.setFitWidth(160);
                        imageView.setPreserveRatio(true);
                    }

                    @Override
                    public void updateItem(File file, boolean empty) {
                        super.updateItem(file, empty);
                        if (empty) {
                            setText(null);
                            setGraphic(null);
                        } else {
                            setText(file.getAbsolutePath().toString());
                            imageView.setImage(new Image(file.getAbsolutePath().toString(), true));
                            setGraphic(imageView);
                        }
                    }
                    });

                grid.add(imageFilesList, imageCol, imageRow);

I've tried every way I can, this is my output, what am I missing? Why is GridPane still loading it in thumbnail size?

image

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Kesh
  • 75
  • 1
  • 1
  • 7

1 Answers1

0

There is no image shown because,

1) The grid view contains ListView imageFilesList, and this list view contains imageFiles. But you are not adding any image files to imageFiles.
2) The image files chosen via fileChooser are added to VBox vl. However this vbox is not added to the gridpane.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153