尝试以缩略图形式将图像显示到网格窗格中的列表视图
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);
我已经尽我所能,这是我的输出,我错过了什么?为什么 GridPane 仍然以缩略图大小加载它?