here's my code.this prompts a exception saying "IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=5.0, vgap=5.0, alignment=TOP_LEFT"
File file = new File("D:\SERVER\Server Content\Apps\icons");
File[] filelist1 = file.listFiles();
ArrayList<File> filelist2 = new ArrayList<>();
hb = new HBox();
for (File file1 : filelist1) {
filelist2.add(file1);
}
System.out.println(filelist2.size());
for (int i = 0; i < filelist2.size(); i++) {
System.out.println(filelist2.get(i).getName());
image = new Image(filelist2.get(i).toURI().toString());
pic = new ImageView();
pic.setFitWidth(130);
pic.setFitHeight(130);
gridpane.setPadding(new Insets(5));
gridpane.setHgap(5);
gridpane.setVgap(5);
pic.setImage(image);
hb.getChildren().add(pic);
}
Adding Items to a
GridPane
is a little different.From the Docs
So in your example, you first need to decide : How many images do I need in one row ?
Lets say your answer is 4, then your code becomes : (There are diff approaches to it, I am writing down the simplest one. You can use anything, loops for rows and colums being a good alternative ;) )