Skip to main content

Does JXLayer work with JDK 5 or 6?

6 replies [Last post]
jacek
Offline
Joined: 2003-08-22

I am trying to fool around with JXLayer in a Java 5 project but I am getting a:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedClassVersionError: Bad version number in .class file

Does JXLayer run on Java 6 only?

Reply viewing options

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

Hello Jacek

Ops.. I accidentally uploaded binaries which were build with JDK 6,
actually JXLayer is JDK 1.5 compatible

I'll fix it shortly, a few more fixes are coming
I'll let you know when it is ready (it will be today)

Thanks!
alexp

jacek
Offline
Joined: 2003-08-22

Thanks, much appreciated.

Quick note: could you add some more sample code to the site or blog that explains how to change the painting at run-time, depending on events being focused.

e.g. I want to create a Flex-style effect when the frame blurs if it loses focus (e.g. a message box pops up) and gets regular painting when it gains focus. I know I have to create an AbstractLayerUI and override processFocusEvent...but after that I am not quite sure how to set a different effect and force a repaint, etc.

E.g.

private JXLayer fx = new JXLayer()

// create custom LayerUI
AbstractLayerUI layerUI = new AbstractLayerUI() {

@Override
protected void processFocusEvent(FocusEvent e, JXLayer l) {
super.processFocusEvent(e, l);
if (e.getID() == FocusEvent.FOCUS_GAINED) {
// ?
} else {
// ?
}
}
};

fx.setUI(layerUI);

jacek
Offline
Joined: 2003-08-22

Forget it: I figured it out by putting 2 and 2 together:

// create custom LayerUI
BufferedLayerUI layerUI = new BufferedLayerUI() {

@Override
protected void processFocusEvent(FocusEvent e, JXLayer l) {
super.processFocusEvent(e, l);
if (e.getID() == FocusEvent.FOCUS_GAINED) {
setLayerEffects(null);
} else {
setLayerEffects(new BufferedImageOpEffect(new BlurFilter()));
}
}
};

Obviously I need to cache the blur effect instead of re-creating it every time, but this is just test code

alexfromsun
Offline
Joined: 2005-09-05

Hello Jacek

I just updated JXLayer binaries,

they a compiled under JDK 1.5 and contain a few important fixes

please download the new jxlayer.jar

Comments about your code:

everything looks good, but I'd like to draw you attention to the fact

that processFocusEvent() is called when JXLayer itself or any of its subcomponents

gain or lose the focus

if you need to apply the effect when the wrapped component is focused

the following code is better:

[code]
protected void processFocusEvent(FocusEvent e, JXLayer l) {
if (e.getID() == FocusEvent.FOCUS_GAINED && e.getComponent() == l.getView()) {
setLayerEffects(null);
} else {
setLayerEffects(new BufferedImageOpEffect(new BlurFilter()));
}
}
};
[/code]

Another concern is about blur effect,

I actually apply it only for a locked layer

(see LockableDemo from the jxlayer-demo.jar)

because blur effect mixes pixels outside of components

and it leads to visual artifacts when active subcomponents are repainted

(please see also the previous thread)

Thanks

alexp

jacek
Offline
Joined: 2003-08-22

That's OK, I am just experimenting with it at this point.

In my case I will most likely make JXLayer the root underneath my JFrame to have one for the entire app.

Quick question: how do I get the x/y coordinates of a child component (could be nested within another layer of components) within the parent JXLayer?

e.g. to draw validation indicators on fields that failed validation....

alexfromsun
Offline
Joined: 2005-09-05

Hello Jacek

SwingUtilities.convertPoint() will help you in you need to convert component coordinate's

I use this method in MouseDrawingDemo from jxlayer.demo package

If you need to find a specific subcomponent,

you should recursively use Component.getComponent(int)

and ask location of a specific component

Thanks

alexp