Iam trying to add some Labels
to a GridPane
.
Those Labels
contain ImageViews which contain some Images
.
My images are .png
-images and are 50 x 50 pixels big.
If my GridPane
is getting to big to display it on my screen, I want to resize my Images. Iam trying this with the methods setFitWidth
and setFitHeight
.
Snipped:
@Override
public void start(Stage stage) {
GridPane gridPane = new GridPane();
int ySize = 5;
int xSize = 5;
int imageSize = 25;
for(int i=0 ; i<ySize ; i++) {
for(int j=0 ; j<xSize ; j++) {
ImageView imageView = new ImageView(new Image(getClass().getResourceAsStream("path.png")));
imageView.setFitWidth(imageSize);
imageView.setFitHeight(imageSize);
Label label = new Label();
label.setGraphic(imageView);
gridPane.add(label, i, j);
}
}
stage.setScene(new Scene(gridPane));
stage.show();
}
The output looks fine:
However, if imageSize
is getting to small, for example 10
, a horicontal spacing appears between the rows:
Is there any way to remove this? I tried to set the label sizes max-properties:
label.setMaxHeight(imageSize);
label.setMaxWidth(imageSize);
with no effect.
Is there any way to remove the spacing? Is it because the images are .png's? Thank you