title: JavaFX how to force Label to update its prefWidth after changing the text?
body: <p>Pretty simple thing actually: I want my <code>Label</code> to update its <code>prefWidth</code> to fit the text into itself whenever the text changes.</p>
  <p>Initially the <code>Label</code>s text is <code>null</code> and the <code>prefWidth</code> is <code>-1.0</code> without setting it manually. So when the <code>Label</code>s text changes at runtime the prefWidth is still <code>-1.0</code> and the <code>Label</code> displays &quot;...&quot; instead of the set text, because it is to small.</p>
  <p>The <code>Label</code> is inside an <code>HBox</code>. That <code>HBox</code>s <code>prefWidth</code> is bound to the sum of its childrens <code>prefWidth</code>s and the <code>HBox</code> has enough space to grow.
  Here's some code to reproduce:</p>
  <pre><code>public class Spielwiese extends Application {
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage window) {
          Label label = new Label();
          Button button = new Button(&quot;Fill Label&quot;);
          button.setOnAction(e -&gt; label.setText(&quot;Some Text&quot;));
          HBox box = new HBox(label, button);
          box.prefWidthProperty().bind(label.prefWidthProperty().add(button.prefWidthProperty()));
  
          window.setScene(new Scene(new StackPane(box)));
          window.setWidth(800);
          window.setHeight(600);
          window.show();
      }
  }
  </code></pre>
  <p>How can I get the <code>Label</code> to update its width to fit its text?</p>
  <p>EDIT: The root of the Scene is a <code>StackPane</code> not a <code>Pane</code>.</p>