1 Reply Latest reply: Jul 27, 2013 7:17 AM by shakir.gusaroff RSS

    Prohibit resizing below a certain window size

    user8929955

      I was wondering if anyone has some useful insights into the following problem:

      I have a scene with a certain initial size. Resizing is allowed, however below certain dimensions the application becomes unusable as not everything can be displayed (Think of an image that should be displayed in a window that is smaller than the image).

      import java.io.IOException;
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;
      
      public class ForceMinSize extends Application {
         
          private double minWidth = 100;
          private double minHeigth = 100;
         
          @Override
          public void start(Stage primaryStage) {
              try {
                  Image img = new Image( getClass().getResource("kajak4_small.png").openStream());
                  ImageView imgView = new ImageView(img);
                 
                  StackPane root = new StackPane();
                  root.getChildren().add(imgView);
                 
                  Scene scene = new Scene(root, 190, 163);
                 
                  primaryStage.setTitle("Force minimal size");
                  primaryStage.setScene(scene);
                  primaryStage.show();
              } catch (IOException ex) {
                  Logger.getLogger(ForceMinSize.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      
          public static void main(String[] args) {
              launch(args);
          }
         
      }
      

      Resizing the components to match the size is not an option. As the dimension properties of the stage are readonly I can only get notified when the size goes below the threshold, but can do nothing about it. The only other solution I can see is disabling resize and only allow the initial dimension (configurable) and fullscreen.