ImagePattern, WritableImage, and Shapes

Joe Andresen Joseph.Andresen at
Tue Dec 11 14:18:01 PST 2012

Hey Fellow JFXers!

I have been working on an issue recently that has to do with 
ImagePattern not updating when it's image changes (ie an animated 
writable image/animated gif).

I do not feel great about my current fix because it requrires some 
public api, which basically copy's how ImageView listens for changes. 
The shape asks if the Paint can change (paint.canIchange()) and then 
adding a listener that is forwarded to the imagepattern's image. When 
fired, the shape marks is fill dirty. Pretty straightforward, but since 
these are in separate packages, public API is created.

Bottom line? Public API just to update an ImagePattern? Seems a bit of 

The Fundamental issue here is that in JavaFX, Paints are more or less 
considered immutable, (the cold hard truth is that sometimes they are 
not, like in the ImagePattern case), mutable paints have their own set 
of problems which one could argue is a snowballing scope for this 
particular issue =(.

Because of this, a workaround can be done by the user assuming immutable 
paints to create a new imagePattern with the newly changed 
WritableImage, but again this is overkill. It seems to me like it 
"should just work".

So we have 2 options:

1) ImagePattern is fundamentally immutable, and a copy of an image is 
taken at constructor time and you the user should construct new 
ImagePattern's if you want it to change.

2) ImagePattern is fundamentally mutable, and can notify its shape of 
changes, this requires that Paints have the notion of being mutable 
(color and gradient would return "not Mutable" when asked).


More information about the openjfx-dev mailing list