Skip to main content

Fading BufferedImageOpEffect?

3 replies [Last post]
Joined: 2007-07-13

Hi people. I've just started using JXLayer and am loving it!

I have a question though. I've got a lockable ui and I set locked effects to this:

new BufferedImageOpEffect(new ColorTintFilter(Color.GRAY, 0.5f));

It tints my panel to a grey colour and looks very nice. However, rather than just having a tinted rectangle, it would be nice if it could taper off at the edges. I guess I would like a gradient.

Is there a standard way of doing this? I can't seem to find one. If there isn't will I have to implement my own LocakableUI?

EDIT: Thinking more about it, I see there is a RadialGradientPaint in java6. How would I incorporate this into the JXLayer locked effect?

Thanks, Paul.

Message was edited by: boomah

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-09-05

Hello Paul

I have never used ColorTintFilter so I can't consult you about that,
I would ask the creators of this filter (is it from SwingX or jhlabs?)

If you need to customize it is writing your own effect,
subclass AbstractBufferedImageOpEffect, apply your filter,
add custom painting and then set the effect to the LocakableUI

to use RadialGradientPaint, please subclass LocakableUI,
override LockedLayerUI.paint() and add custom painting there
(isLocked() method will tell you if the ui is locked)

by the way, it can also be implemented as the layerEffect
the good thing about that is that you will be able to apply it
to any AbstractBufferedLayerUIs


Joined: 2007-07-13

Thanks alexp.

I thought someone might have known about one that currently existed. Not to worry though, I wrote my own and will put it here in case anyone else needs it:


protected void paintLayer(Graphics2D g2, JXLayer l) {

super.paintLayer(g2, l);

int width = l.getWidth();

int height = l.getHeight();

g2.setPaint(new RadialGradientPaint(new Point2D.Double(width / 2, width / 2), width * 0.75f, new Point2D.Double(width / 2.0, width / 2.0), new float[]{0.0f, 0.7f, 1.0f},new Color[]{new Color(0,0,0,128),new Color(0,0,0,64), new Color(0,0,0,0)}, RadialGradientPaint.CycleMethod.NO_CYCLE, RadialGradientPaint.ColorSpaceType.SRGB, AffineTransform.getScaleInstance(1.0, (double)height / (double)width)));

g2.fillRect(0, 0, width, height);


Joined: 2005-09-05

Hello Boomah

Good job!

Have a nice day