title: How can I assign a css style to an on the fly created element?
body: <p>I'm creating a rectangle in code and placing it inside a <code>HBox</code> created in scenebuilder. I then apply an already existing css style to it. The rectangle doesn't even show unless I specify a height and width when creating it (even though the css style already specifies height and width). However when I do manage to get it to show, the css style is not applied. I have no idea why this is happening and am hoping that someone can help me! Thanks</p>
  
  <pre><code>Rectangle rect = new Rectangle();
  timesheetSlots.getChildren().addAll(rect);
  rect.getStyleClass().add("timesheetSlot");
  </code></pre>
  
  <pre class="lang-css prettyprint-override"><code>.timesheetSlot{
      -fx-background-color: #ff6600;
      -fx-width: 20;
      -fx-height: 25;
      -fx-cursor: hand;
  }
  .timesheetSlot:hover{
      -fx-background-color: #ffffff;
  }
  .timesheetSlotSelected{
      -fx-background-color: #1Eff00;
      -fx-max-height: 25;
      -fx-max-width: 20;
      -fx-cursor: hand;
  }
  </code></pre>