Desktop Java

JavaFX Tip 18: Path Clipping

I recently noticed that the PopOver control, which I committed to the ControlsFX project, does not properly clip its content. It became obvious when I was working on the accordion popover for the FlexCalendarFX framework. Whenever the last titled pane was expanded the bottom corners were no longer rounded but square. After placing a red rectangle as content to the titled pane it became clear to me that I forgot to add clipping. The following picture shows the problem.
 
 
 
 
 
 
bildschirmfoto-2015-02-18-um-12-20-09

Normally clipping in JavaFX is quite easy. All it takes is an additional node and a call to setClip(node). However, normally this clip is a simple shape, like a rectangle. In the PopOver case the clip had to be a path, just like the original path that was used for the shape of the PopOver. Why a path? Because the popover, when “attached” to an owner, also features an arrow pointing at the owner. See screenshot below.

bildschirmfoto-2015-02-18-um-12-38-53

So the good thing was that the original path gets constructed based on a list of path elements. These are not nodes and can be reused for a second path. When I tried this the result was a PopOver that only consisted of a border with no content at all.

bildschirmfoto-2015-02-18-um-12-25-23

The reason for this was the fact that the path was not filled. Once I set a fill on the clip path the result was what I was aiming for.

bildschirmfoto-2015-02-18-um-12-25-40

Now the PopOver control clipped its content correctly. The image below shows the final result.

bildschirmfoto-2015-02-18-um-12-19-55

Some might say that this is just a minor detail and they are right, but it is this attention to detail that makes an application stand out and look professional.

The image below shows how the PopOver is used within FlexCalendarFX.

bildschirmfoto-2015-02-17-um-15-00-39

Reference: JavaFX Tip 18: Path Clipping from our JCG partner Dirk Lemmermann at the Pixel Perfect blog.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button