Skip to main content

RescaleOp ignored in LockableUI

2 replies [Last post]
chuck102
Offline
Joined: 2008-11-27
Points: 0

I am trying a simple case of using LockableUI with a call to setLockedEffects()

The problem is that I expect the RescaleOp to scale the image to zero and thus darken the locked components but it does not have any effect.

Any suggestions?

The demo code is below.

thanks

Chuck

import java.awt.Dimension;
import java.awt.image.RescaleOp;
import javax.swing.*;
import org.jdesktop.jxlayer.JXLayer;
import org.jdesktop.jxlayer.plaf.effect.BufferedImageOpEffect;
import org.jdesktop.jxlayer.plaf.ext.LockableUI;
public class Test extends JFrame {
private class LockUI extends LockableUI {
LockUI() {
setLockedEffects(new BufferedImageOpEffect(new RescaleOp(0.0f, 0f, null)));
}
}

Test() {
super("test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();
panel.add(new JLabel("Label 1"));
panel.add(new JLabel("Label 2"));
panel.add(new JLabel("Label 3"));

JXLayer layer = new JXLayer(panel);
LockUI lockUI = new LockUI();
layer.setUI(lockUI);
lockUI.setLocked(true);
add(layer);
setPreferredSize(new Dimension(800, 500));
pack();
setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Test();
}
});
}
}

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
Points: 0

Hello Chuck

I have always used a constructor of RescaleOp that takes arrays of scales and offsets,

It's better to ask why the other one works this way on Java2D forum

I would make it dark this way:

[code]
float[] scales = { 0f, 0f, 0f, .5f};
float[] offsets = new float[4];
RescaleOp rop = new RescaleOp(scales, offsets, null);
setLockedEffects(new BufferedImageOpEffect(rop));
[/code]




By the way, what was the reason to subclass LockableUI?

Thanks

alexp

chuck102
Offline
Joined: 2008-11-27
Points: 0

Thanks for the help. The RescaleOp constructor that uses float arrays worked.
The non-array RescaleOp contructor seemed simple enough that I thought my problem was with my use of the JXLayer APIs.

I created a subclass of LockableUI because I was playing around with the code. I realize that for the simple case I submitted, I could have used an instance of LockableUI directly.

Thanks again. The JXLayer is a very useful package.

Chuck