While learning JavaFX 8 I have found out that nodes are not clipped to the region given by the layout. I applied a scale transform and the Pane containing some random Rectangles happily overlapped everything else in the window.
I have tried something like the following code without success. What is the correct pattern for clipping nodes to their layout region?
Also, I have implemented the scaling by implementing onZoom which responds to the pinch gesture on my MacBook Air according to the code below (the anchor point for the scaling is not correct right now but I will solve that later). The problem is that the onZoom event is not responding unless I pinch on one of the rectangles. The Pane itself is not responding unless it gets a bubbled event from one of the rectangles. How can I make the Pane respond to onZoom events?
CORRECTION: The Pane does not respond in negative coordinates. It does however respond for positive coordinates. I guess I have to put a Pane inside a Pane and let the parent Pane transform the child Pane to catch the events properly.
Stefan K Larsson
Joined: Jul 09, 2014
I eventually solved the problem. The following snippet clips the component correctly.
I think the solution you posted in your follow up post is the correct way to clip a region to it's layout bounds, so that it does not paint children outside those bounds.
For your second question, maybe put the Pane in a Group rather than another Pane.
If you have time, you might want to view a video on JavaFX layout from a past JavaOne. See especially the slide at 46 minutes and 3 seconds which defines the layout bounds types and calculations. You could also try this little demo on layout bounds.