VOOZH about

URL: https://www.javacodegeeks.com/2015/02/javafx-tip-18-path-clipping.html

⇱ JavaFX Tip 18: Path Clipping - Java Code Geeks


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.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
JavaFX
πŸ‘ Photo of Dirk Lemmermann
Dirk Lemmermann
February 24th, 2015Last Updated: February 19th, 2015
0 188 1 minute read
Subscribe

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

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz