jQuery in Action, 2nd edition*
The moose likes JavaFX and the fly likes Scaling and Node clipping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JavaFX
Bookmark "Scaling and Node clipping" Watch "Scaling and Node clipping" New topic
Author

Scaling and Node clipping

Stefan K Larsson
Greenhorn

Joined: Jul 09, 2014
Posts: 10
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

Joined: Jul 09, 2014
Posts: 10
I eventually solved the problem. The following snippet clips the component correctly.


John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 144
    
    9
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.
 
GeeCON Prague 2014
 
subject: Scaling and Node clipping