0

Whenever I print the label size in the following code I get 0.0 as the width when it's somewhere around 290.

private void initializeComponents() {
    setId("main_window");
    setAlignment(Pos.TOP_LEFT);
    String sn = "scene_main.css";
    String stylesheet = getClass().getResource(sn).toExternalForm();
    getStylesheets().add(stylesheet);
    welcome.setTranslateX((Main.window.getWidth() - welcome.getWidth()) / 2);
    welcome.setTranslateY(5);
    options.setTranslateX((Main.window.getWidth() - options.getWidth()) / 2);
    options.setTranslateY(welcome.getTranslateY() + welcome.getHeight() + 20);
    getChildren().add(welcome);
    getChildren().add(options);
}

private Label welcome = new Label("Welcome to your Bank!");
private Label options = new Label("Choose a user.");

This code is called AFTER the stage is shown. What can I do to update the width of the labels?

Philip Vaughn
  • 606
  • 6
  • 20
  • So apparently, according to the duplicate question link, there is literally no way to get the size of a node created after the stage is shown. Great job java. I think this needs a MAJOR update. – Philip Vaughn Oct 29 '14 at 20:16

1 Answers1

1

Ok, so after some long hours of testing and playing around I noticed that not only do you have to ask for the sizes of nodes AFTER the stage is shown you have to add them to their containers BEFORE you show the stage. So basically you have to initialize a container, add that container to a scene, add all your components to the container, and THEN show the stage. After these steps you can freely ask for the sizes of nodes and those sizes will be correct.

Now, with this in mind I'm still not sure how to ask for the size of a node that is initialized AFTER the stage is shown. Basically, I'm still not sure how to refresh a stage so everything in it is updated. When building any kind of application I basically have to create everything right off the get go and I do not necessarilly wish to do that. Sometimes (maybe a game design) I may not wish to create everything at once. I may wish to create things only as the player get to it. It'd really be helpful to be able to update the sizes of nodes mid-flight (if you know what I mean). Just let me know if anyone knows a way to do this.

Philip Vaughn
  • 606
  • 6
  • 20