title: How to center/wrap/truncate Text to fit within Rectangle in JavaFX 2.1?
body: <p>I need to dynamically create Rectangles over Pane in JavaFX 2.1. Next I need to center/wrap/truncate Text over the Rectangle. The text has to fit within the rectangle. I am able to center and wrap the text with the following code, however, if the text length is too long, it will appear out of the rectangle. I want to create the behavior like Label within StackPane, essentially if the Rectangle grows, the Text will grow with it but always remain in the center of the Rectangle and if the Text cannot fit within the Rectangle, it will be truncated accordingly. </p>
  
  <pre><code>Rectangle r;
  
  Text t;
  
  ...
  
  //center and wrap text within rectangle
  
  t.wrappingWidthProperty().bind(rect.widthProperty().multiply(0.9);
  
  t.xProperty().bind(rect.xProperty().add(rect.widthProperty().subtract(t.boundsInLocalProperty().getValue().getWidth().divide(2)));
  
  t.yProperty().bind(rect.yProperty().add(rect.heightProperty().divide(2)));
  
  t.setTextAlignment(TextAlignment.CENTER);
  
  t.setTextOrigin(VPos.CENTER);
  </code></pre>
  
  <p>What properties can I use to achieve that or is there a better way of doing this?</p>