我正在尝试使用ImageViews数组填充TilePane。到目前为止,这是我尝试过的方法,它可以运行,但照片不会出现在磁贴窗格中。有什么想法吗?
我尝试使用一个循环一次添加图像,然后一次全部添加(给我一个重复的子错误)。
public class AlbumC implements Initializable{
@FXML
public MenuItem returnToAlbums;
@FXML
public TilePane preview;
User currentUser = Login.newUser;
ArrayList <ImageView> allImages;
public AlbumC() {
}
@FXML
public void returnToAlbumPage() throws Exception {
ChangeScene nextScene = new ChangeScene("../gui/user.fxml",600,400);
nextScene.setTitle(currentUser.getUsername() + "'s Albums");
nextScene.currentScene();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
allImages = new ArrayList<ImageView>();
preview = new TilePane();
System.out.println("Stock albums: " + currentUser.getUserAlbums().get("stock").getPhotoList().size());
createImages();
}
public void createImages() {
Image temp;
for(int i = 0; i < currentUser.getUserAlbums().get(UserC.albumOpened).getPhotoCount(); i++) {
temp = new Image(currentUser.getUserAlbums().get(UserC.albumOpened).getPhotoList().get(i).getPath().toString());
System.out.println("path: " + currentUser.getUserAlbums().get(UserC.albumOpened).getPhotoList().get(i).getCaption());
allImages.add(new ImageView(temp));
}
for(int i = 0; i < allImages.size(); i++) {
preview.getChildren().add(allImages.get(i));
}
}