Reflecting on Reflections: The JavaFX Reflection Effect

I have been playing with JavaFX recently, and it has to be said that I’ve been having a really pleasant time. The API is really well documented, and the code itself is simple, intuitive and easy get the hang of.

One of the tasks that I had planned for today was to add reflections to the PDF Page Flow mode in our Java PDF Viewer that I have been converting from Java3D to JavaFX.

I was pleasantly surprised when I came to read the Reflection Documentation to find that adding reflections to Nodes is in fact a single line. It really is as simple as this:

ImageView imView = new ImageView();
imView.setEffect(new Reflection());

And now your ImageView has a reflection applied to it!

Unfortunately however, this addition revealed something not so desirable in the output. Here’s a screenshot:

As you can see, there are two ImageViews that overlap, with the one on the right obscuring half of the one on the left. This isn’t reflected on the reflections however, as the middle of the two images merge together incorrectly. The fix should be quite simple, the reflections just need to be cropped to the visible area of the Nodes that they reflect.

I have created a bug report, so hopefully there will be a fix in the future!

I have written several articles on converting our Java3D usage into JavaFX and you can read the other articles here.

The following two tabs change content below.
Leon is a Developer at IDRsolutions, focusing mainly on development of the PDF to HTML5/SVG converter. He was a speaker at JavaOne 2012, co-presenting a session titled 'Lessons Learned in Writing a PDF-to-JavaFX Converter for NetBeans'.

Related Posts:

Leon Atherton

About Leon Atherton

Leon is a Developer at IDRsolutions, focusing mainly on development of the PDF to HTML5/SVG converter. He was a speaker at JavaOne 2012, co-presenting a session titled 'Lessons Learned in Writing a PDF-to-JavaFX Converter for NetBeans'.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>