title: JavaFX: Buttons with same width and size to text
body: <p>A button can always auto-resize its width to its contents (<code>textProperty</code>), but I need something more.</p>
  
  <p>I have a group of Buttons; each has its own text. I need all the buttons to have the same width, but at the same time, I want this same width to be as small as possible (such that none of the buttons have extra spaces nor ellipsis).</p>
  
  <p>I thought it would be easy, until I realized that <code>getWidth()</code>, <code>getlayoutBounds.getWidth()</code> and <code>getlayoutBoundsInParent().getWidth()</code> do not return the calculated width.</p>
  
  <p>Initially I was directly binding all the properties (<code>prefWidthProprety()</code> to <code>widthProperty()</code> etc), but eventually I fell back to manual mode to investigate:</p>
  
  <pre><code>Button buttonA; // With original text "hello world"
  
  buttonA.setText("Testing new String. This is very long so the width will be very big.");
  buttonA.layout();
  buttonA.requestLayout();
  
  Platform.runLater(() -&gt;
  {
      System.out.println(buttonA.getWidth()); // Gives me old value
      System.out.println(buttonA.getlayoutBounds.getWidth()); // Gives me old value
      System.out.println(buttonA.getlayoutBoundsInParent().getWidth()); // Gives me old value
  });
  </code></pre>
  
  <p>So now, what options do I have?</p>