Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scaling and Node clipping

 
Stefan K Larsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two questions in this post.

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
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I eventually solved the problem. The following snippet clips the component correctly.


 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a feature request for this functionality:
RT-17441 "add boolean clipContent property to Region to make it easier to turn clipping on/off for layout containers"

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic