0

I have a GridPane and in all of the cells ImageView containing Images. I successfully managed to make the GridPane resizable when I change the window size.

The problem is that when the GridPane gets bigger the images won't grow. I know you can make them fit when it's in full-screen by:

imageView.setFitHeight(100);
imageView.setFitWidth(100);

With this code, the images will be too big when not in full-screen.

I want to have them in Window Mode fit perfectly(Fit(80)) in the cell, as well as in Fullscreen(Fit(100)).

My (not so good-looking) idea was to have a method something like:

if(stage.inFullscreen) { setFitHeight/Width(100)};
if(stage.inWindowscreen) { setFitHeight/Width(80)};

Is there any other more elegant way?

Part of my Code:

<GridPane fx:id="Board" layoutY="-1.0" prefHeight="800.0" prefWidth="836.0">
              <columnConstraints>
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
...

Abra
  • 19,142
  • 7
  • 29
  • 41
mip42
  • 65
  • 6
  • I think if you posted a [mcve] it would help people to answer your question. You can [edit] your question. – Abra Dec 18 '19 at 20:07
  • 3
    What happens if you use `StackPane` as the root nodes in the `GridCells` and bind the `ImageViews'` width and heights to the `StackPanes'` width and height? `img_view1.fitWidthProperty().bind(scrollpane_imageview1.widthProperty()); img_view1.fitHeightProperty().bind(scrollpane_imageview1.heightProperty());` Where `ScollPane` is replaced by `StackPane`. – SedJ601 Dec 18 '19 at 20:15
  • Related: [How to resize an image when resizing the window in JavaFX](https://stackoverflow.com/questions/22993550/how-to-resize-an-image-when-resizing-the-window-in-javafx) – jewelsea Dec 18 '19 at 20:47

0 Answers0