0

I have two StackPanes side-by-side in a SplitPane. Now, I'm trying to add a Rectangle to both of these StackPanes - which would fill the whole StackPane. So I tried this:

rect.widthProperty().bind(stack.widthProperty());
rect.heightProperty().bind(stack.heightProperty());

However, in my application, this causes the StackPanes to slowly resize all the time to infinity, for a reason that I can't quite grasp... I could not reproduce this in a simple test application.

I'm not sure how to fix or to get to the bottom of this, any ideas for a "workaround" or what could possibly cause this behavior?

user38725
  • 876
  • 1
  • 10
  • 26
  • I also couldn't reproduce that error. Maybe there is something else that size is bound to StackPane? – Maciej Dobrowolski Apr 09 '19 at 08:51
  • I [noticed](https://stackoverflow.com/questions/55292973/changing-color-attributes#comment97371199_55292973) the effect while reading this [exercise](https://stackoverflow.com/q/55292973/230513). It looks expected behavior: "StackPane does not clip its content by default, so it is possible that children's bounds may extend outside its own bounds…" – trashgod Apr 09 '19 at 09:29
  • Given it seems the rectangle should cover the entire region, you could try using `rect.setManaged(false)`. That will stop the `StackPane` from including the rectangle in its bounds calculations. It will also stop the `StackPane` from laying out the rectangle, but that shouldn't be an issue; assuming you don't set the rectangles `x`, `y`, `layoutX`, or `layoutY` the rectangle will be placed at (0,0) and have the same dimensions as the `StackPane` (due to the bindings). – Slaw Apr 09 '19 at 09:54
  • Though if the reason you're adding the rectangles is to simulate a background on the `StackPane`s, you'll probably be better off setting an actual background. – Slaw Apr 09 '19 at 09:57

0 Answers0