1 Reply Latest reply: Jan 23, 2013 5:59 AM by 983777 RSS

    How to properly resize a group

    983777
      I have following problem:
      To fit a group properly into a pane I want to resize it. Currently, I use setScale.. . The size changes, however the bounds remain the same.

      What is the correct way to achieve that?

      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TitledPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Circle;
      import javafx.stage.Stage;
      
      
      public class JavaFXApplication1 extends Application {
          
          @Override
          public void start(Stage primaryStage) {
            
              HBox root = new HBox();
                     
              VBox left = new VBox();
              root.getChildren().add(left);
              
              //create a titled pane with the max width of 100
              TitledPane tp = new TitledPane();        
              tp.setPrefWidth(100);
           tp.setMaxWidth(100);
           tp.setText("Notification");
           tp.setCollapsible(false);
              left.getChildren().add(tp);
              
              StackPane stackPane = new StackPane();
           stackPane.setPrefHeight(180);
           stackPane.setPrefWidth(100);
           stackPane.setMaxWidth(100);
           tp.setContent(stackPane);
              
                
             //just a second node beneth the Titled Pane   
              root.getChildren().add(new Button("Test"));
                      
                                   
             // now create a larger circle, scale it down
             // and add it to the stackpane within the titdled pane
             Group gnote = new Group();        
             Circle cleft = new Circle(100,Color.GOLDENROD);
             gnote.getChildren().add(cleft);
             gnote.setScaleX(0.5);
             gnote.setScaleY(0.5);              
             stackPane.getChildren().add(gnote);
              
              Scene scene = new Scene(root, 300, 250);        
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
              
          }
      Edited by: skauf on 17.01.2013 07:29