Saturday, July 17, 2010

My Bads

Just a quick update (long overdue - sorry!) to correct a couple of errors in my last two posts.

First, going all the way back to my post So What's It All Good For?, I realized while using my 'X' shape on another control that I had flubbed one of the coordinates in the SVG path.  This made the 'X' look a little hinkey.  Although it was really only noticeable at larger sizes, I went back and fixed the SVG path in that post.  Now the 'X' checkbox looks better.


My second mistake was of a larger variety.  I incorrectly claimed in my Into the Background post that you couldn't use a gradient as the background of a ScrollView because once you added other Nodes, the CSS engine would throw an exception.  Turns out it was user error.

You see, I was assigning the gradient to the -fx-background property in the .scene style.  The fact is that this property must evaluate to a color, not a gradient, because it is used later in the default Caspian style sheet as the base color from which other gradients are calculated.  For some reason the CSS engine objected to me trying to force it to using a gradient as a color stop in another gradient.  Go figure!

This is the reason that the error would only manifest once another control was added to the scene as that was when the gradient-based-on-gradient calculation would be triggered.

My mistake was kindly pointed out by David Grieve in response to my initial bug report here.  I have also updated the original article to demonstrate a variation of the technique that David suggested.  Thanks David!


Hopefully these kinds of mistakes will be less likely to happen in the future now that some nice documentation of the JavaFX CSS engine exists.  There is also a new JIRA case opened to add better error handling and reporting to the CSS engine, which should also be a big help.

p.s. If you haven't signed the petition to open source the JavaFX runtime, please do so now!  Having access to the source code could also help avoid these kinds of "misunderstandings" in the future.