1

I'm now trying for hours but I do not get it...

My app should show some images inside a GridView.

The amount of columns is defined/configurable. Now I want to distribute the images to use all width, and use the scrollpane to scroll down. I'm sure this is easy to achieve but somehow I struggle.... Thanks very much!

My tries using

view.setFitWidth(scrollpane.getWidth()/max_cols)

and similar failed...

int imagesShown=0;
for(ImageObject i : images){
    int row = (int)Math.floor(imagesShown/max_cols)+1;
    int col = imagesShown - (row-1)*max_cols + 1;
    imagesShown++;
    imageGridPane.add(i.view, col, row);
 }
il_raffa
  • 5,090
  • 129
  • 31
  • 36
SalkinD
  • 753
  • 9
  • 23
  • 1
    I would advice you to use a TilePane instead of a GridPane, as it becomes difficult in GridPane to handle images if you decrease / increase the stage size. I complete example can be found in the answer to [Working on Creating Image Gallery in JavaFX. not able to display image properly](http://stackoverflow.com/questions/27182323/working-on-creating-image-gallery-in-javafx-not-able-to-display-image-properly). – ItachiUchiha Jun 17 '15 at 18:06
  • seems to be the right thing for me but it completely ignores setPrefColumns. just no reaction. no scaling, no wrap. tilepane.setMaxWidth does wrap to new line, but brings again the need to know the width of scrollpane... – SalkinD Jun 18 '15 at 15:33
  • thanks found workaround. TilePane in combination with Platform.runLater(()->{image.setFitWidth(tilepane.getWidth()/cols);}); – SalkinD Jun 18 '15 at 16:28

0 Answers0