2

i am facing problem to developed a demo JavaFX program for image viewing as a newbie. here i have an ImageView in BorderPane center position which is wrapped with a StackPane and VBox. where StackPane is always grow with VBox and i bind ImageView with StackPane Width and Height property so that my ImageView will change its setFitHeight and Weight when i resize window. it works fine as i want but problem is when window resized from maximum the image don't resize its Height. i found that StackPane's heightProperty change listener don't call. So i to solve this problem to archive my goal.? is its some kinds JavaFX bug or my lacking knowledge?

here is my fxml code for image view:

   <center>
  <VBox fx:id="imageVBox" alignment="CENTER" BorderPane.alignment="CENTER">
     <BorderPane.margin>
        <Insets />
     </BorderPane.margin>
     <StackPane fx:id="stackPane" VBox.vgrow="ALWAYS">
        <ImageView fx:id="imageView" fitHeight="250.0" fitWidth="300.0" nodeOrientation="INHERIT" onDragDropped="#getDragImage" onDragOver="#dragOver" pickOnBounds="true" preserveRatio="true" StackPane.alignment="CENTER">
           <viewport>
              <Rectangle2D />
           </viewport>
        </ImageView>
     </StackPane>
  </VBox>

my java code which bind ImageView with StackPane:

        imageView.fitWidthProperty().bind(stackPane.widthProperty());
        imageView.fitHeightProperty().bind(stackPane.heightProperty());

the problem i faced:

  1. my program window when i run it

my program window when i run it

  1. maximize window

maximize window

  1. when i resize it to default the problem occured, image don't resize as expected

when i resize it to default the problem occured, image don't resize as expected

Rhidoy
  • 123
  • 1
  • 12

1 Answers1

4

well, i found the problem from that post answer JavaFX - BorderPane/StackPane not resizing after children changed and the problem was that i didn't give StackPane any minimum size which is required to do the clipping. so i'm posting the answer if it helps someone.

so my final solved binding code is like below:

stackPane.setMinSize(0, 0);
imageView.fitWidthProperty().bind(stackPane.widthProperty());
imageView.fitHeightProperty().bind(stackPane.heightProperty());
Community
  • 1
  • 1
Rhidoy
  • 123
  • 1
  • 12