ImageView in GridPane: Bildgröße

iTobi97

Aktives Mitglied
Hallo liebe Community, ich bin einmal wieder auf das Problem mit ImageViews in Gridpanes gestoßen. Ich habe ein Gridpane mit jeweils einem ImageView in einer Zelle. Allerdings schaffe ich es nicht, die Größe der ImageViews zu begrenzen, sodass diese nicht in Originalgröße angezeigt werden. Auch mit Constraints hatte ich bisher noch keinen Erfolg. Scheinbar will sich der ImageView einfach nicht an das GridPane anpassen.

Hat jemand von euch vielleicht Tipps und Lösungsvorschläge?
Vielen Dank schon einmal im Voraus

Mein Code:
Java:
gameBoard.setGridLinesVisible(true);
        gameBoard.setMaxWidth(100);
        gameBoard.setMaxHeight(100);
        ColumnConstraints col1 = new ColumnConstraints();
        col1.setPercentWidth(10);
        ColumnConstraints col2 = new ColumnConstraints();
        col2.setPercentWidth(10);
        RowConstraints row1 = new RowConstraints();
        row1.setPercentHeight(10);
        RowConstraints row2 = new RowConstraints();
        row2.setPercentHeight(10);

        gameBoard.getColumnConstraints().addAll(col1,col2);
        gameBoard.getRowConstraints().addAll(row1,row2);
        Image image = new Image("file:" + filePaths.get(0));
        for(int i = 0; i < 12; i++){
            for(int j = 0; j < 12; j++){
                ImageView imageView = new ImageView(image);
                imageView.setFitHeight(10);
                imageView.setFitWidth(10);
                imageView.setPreserveRatio(true);
                gameBoard.add(new ImageView(image), i, j);

            }
        }
 
Vielleicht funktioniert durch die HGrow und VGrow methoden?

Java:
gridPane.setHgrow(image[i][j], Priority.ALWAYS);
gridPane.setVgrow(image[i][j], Priority.ALWAYS);
GridPane.setFillWidth(image[i][j], true);
GridPane.setFillHeight(image[i][j], true);

Lg

Edit: Oder habe ich dich falsch verstanden? 😛
 

Zurück
Oben