Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124318

Stage.setScene and sizing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 7u10
    • javafx
    • Ubuntu 12.10

      If I set the stage's dimensions then show it, the controls and layouts are sized appropriately to fit it.

      But if I switch the scene later, the new scene's layouts are sized at their defaults instead of the stage's current dimensions. If I resize the window with the mouse after switching the scene, the layout ends up getting adjusted to the stage's new dimensions accordingly. This seems a little inconsistent.

      The application below demonstrates this if you click the button to switch the scene:

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextArea;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;

      /**
       *
       *
       */
      public class Main extends Application {
          
          @Override
          public void start(final Stage primaryStage) {
              BorderPane root = new BorderPane();
              
              //Top of the scene.
              Button button = new Button("Click Me!");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      BorderPane root = new BorderPane();
                      TextArea textArea = new TextArea();
                      textArea.setText("Hello World!");
                      root.setCenter(textArea);
                      
                      Scene scene = new Scene(root);
                      scene.setFill(Color.AQUA);
                      primaryStage.setScene(scene);
                  }
              });
              root.setTop(button);
              
              //Middle.
              TextArea textArea = new TextArea();
              textArea.setText("Hello World!");
              root.setCenter(textArea);
              
              Scene scene = new Scene(root, 300, 250);
              
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.setWidth(500);
              primaryStage.setHeight(300);
              primaryStage.show();
          }

          /**
           * The main() method is ignored in correctly deployed JavaFX application.
           * main() serves only as fallback in case the application can not be
           * launched through deployment artifacts, e.g., in IDEs with limited FX
           * support. NetBeans ignores main().
           *
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
      }

            msladecek Martin Sládeček
            hwagnerjfx Hans Wagner (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: