0
    imageGrid = new GridPane();
    imageGrid.prefWidthProperty().bind(gallerie.widthProperty().multiply(1.00));
    imageGrid.prefHeightProperty().bind(gallerie.heightProperty().multiply(0.9));
    imageGrid.setPadding(new Insets(20, 20, 20, 20));
    imageGrid.setHgap(20);
    imageGrid.setVgap(20);
    imageGrid.setStyle("-fx-background-color: #154BE5");

... ... ...

static void loadCurrentImages(ArrayList<File> imageFiles) {

    ArrayList<ImageView> ivs = new ArrayList<>();
    int i = 0;
    int k = 0;
    int j = 0;
    for (File f : imageFiles) {
        ImageView iv = new ImageView();
        iv.setFitWidth(100);
        iv.setPreserveRatio(true);
        iv.setSmooth(true);
        iv.setImage(new Image(f.toURI().toString()));
        ivs.add(iv);
        imageGrid.add(ivs.get(i), k, j);
        i++;
        k++;
        if(k > imageGrid.widthProperty().intValue() / 100){  //???????
            k = 0;
            j++;
        }
    }
}

in the last if clause I want to use the current size of the grid but i have no idea how to gtet it because itself its bound to another size (gallerie)

i want to get the current int value

BIKERSAN
  • 1
  • 2
  • Are you sure you don't want a `FlowPane`? If your nodes all have the same width, This layout should be the equivalent of a `GridPane` plus automatic wrapping of the "lines" that updates itself automatically, if the `FlowPane` is resized. Furthermore if `galerie`and `imageGrid` have a common parent, there's probably a better way to keep the width the same than binding. Choose the proper layouts as ancestors... – fabian Nov 07 '19 at 23:28

1 Answers1

0

The layout bounds of a node will not be computed instantly. Will be computed only when the nodes are rendered in the scenegraph. To get them as you desired, you need to explicitly request for layouting.

node.applyCss();
node.requestLayout();

Please keep a note that using the above two lines may have a minor performance impact.

Ignoring all your code issues (static, name conventions, actual logic..), below is the quick idea of what you can try for.

static void loadCurrentImages(ArrayList<File> imageFiles) {

    ArrayList<ImageView> ivs = new ArrayList<>();
    int i = 0;
    int k = 0;
    int j = 0;
    for (File f : imageFiles) {
        ImageView iv = new ImageView();
        iv.setFitWidth(100);
        iv.setPreserveRatio(true);
        iv.setSmooth(true);
        iv.setImage(new Image(f.toURI().toString()));
        ivs.add(iv);
        imageGrid.add(ivs.get(i), k, j);
        i++;
        k++;

        // Requesting layout
        imageGrid.applyCss();
        imageGrid.requestLayout();

        if(k > imageGrid.widthProperty().intValue() / 100){  //???????
            k = 0;
            j++;
        }
    }
}
Sai Dandem
  • 8,229
  • 11
  • 26