Wednesday, 9 April 2014

FX 2.2 to FX 8.0 Part 1 (3rd party controls)

Java FX 8.0 was released a few weeks ago and since then I have been working at ironing out the glitches in my application, as unfortunately it wasn't 100% compatible. So I thought I'd share my experience for others.

I encountered about 10 problems in getting the app to look and work correctly with FX 8.0, which I detail here in nine short blogs.

My first challenge was actually just getting the app to compile in FX 8.0 without errors !

The problem was that I had some 3rd party controls that were extending SkinBase, which was a non-public class in 2.2  It has now been made public in 8.0 but with API changes, so it isn't directly compatible. Depending on how the control handles any key or mouse events, converting from the one to the other isn't necessarily a straightforward exercise and results in the control only being able to work in FX 8.0 afterwards.  

After some thought I decided that I wanted my app to be able to work correctly in both FX 2.2 and 8.0, so that transitioning my user base over from the former to the latter didn't have to be an all or nothing scenario.  So the offending controls were changed to implement Skin instead of extending SkinBase (thankfully I had access to the control's source code, some of which I had previously customised). 

Implementing Skin is fairly easy and basically involves adding 3 methods which are mostly one liners (getSkinnable, getNode, and dispose), and then removing the super( X,Y ) call in the constructor where X is now returned by getSkinnable(). Also remove the getChildren().add( Z ) line if present, where Z is now returned by getNode().

In both cases, either implementing Skin or making changes for SkinBase, moving behavior is more complex and involves a bit of coding especially for handling any KeyEvent's.

Once I had reworked the offending controls the app successfully compiled :-), but my joy was short lived .... see part 2.

No comments:

Post a Comment