Skip to main content

Weird effect when locking UI

2 replies [Last post]
boomah
Offline
Joined: 2007-07-13
Points: 0

Hi all. I have a problem with JXLayer in that when I lock the UI, the underlying image is updated. I don't think this should happen.
Here is my code:
import org.jdesktop.jxlayer.JXLayer;
import org.jdesktop.jxlayer.plaf.ext.LockableUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JXLayerTest extends JFrame {
public JXLayerTest() {
setDefaultCloseOperation(EXIT_ON_CLOSE);

JLabel label = new JLabel("Look at this text");
JXLayer<JComponent> layer = new JXLayer<JComponent>(label);
final LockableUI layerUI = new LockableUI();
layer.setUI(layerUI);

JButton button = new JButton("Click Me");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
layerUI.setLocked(!layerUI.isLocked());
}
});

JPanel mainPanel = new JPanel(new FlowLayout());
mainPanel.add(layer);
mainPanel.add(button);

add(mainPanel);
pack();
setLocationRelativeTo(null);
setVisible(true);
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new JXLayerTest();
}
});
}
}

and here are the results:
not locked: http://i.imgur.com/BlbOb.png
locked: http://i.imgur.com/sh71M.png
as you can see, the text has changed. I would not expect it to. This was on Ubuntu 10.04. You don't see the problem on XP as text isn't antialiased.

Is there a way to stop this from happening?

Thanks, Nick.

P.S. Sorry about the formatting... I've tried a lot but can't get it any better.

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 Nick
The LockedUI paints the layer's content to the intermediate image with in the locked state,
looks like it is painted differently in this case. Try to play with rendereing hints for the image's graphics,
in the overridden paintLayer() method, I can't think anything else from the top of my head.
to format the source code wrap it with [ code ] [ / code ] without blanks inside

Thanks
alexp

boomah
Offline
Joined: 2007-07-13
Points: 0

Hi Alex.

Thanks for the reply.

When you say it's being painted differently in this case and I should try changing the hints in the overridden paintLayer() method, do you mean that I should override the paintLayer() method on my LockableUI?.

The code I posted is using the standard LockableUI class.

I've updated the code to turn anti alias off and added a blue background to make the effect more apparent. The anti alias off doesn't seem to have any effect.

Do you think it is just something Ubuntu is doing?

Thanks, Nick.

<br />
import org.jdesktop.jxlayer.JXLayer;<br />
import org.jdesktop.jxlayer.plaf.ext.LockableUI;<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;</p>
<p>public class JXLayerTest extends JFrame {<br />
    public JXLayerTest() {<br />
        setDefaultCloseOperation(EXIT_ON_CLOSE);<br />
        JLabel label = new JLabel("Look at this text");<br />
        JPanel panel = new JPanel();<br />
        panel.setBackground(Color.BLUE);<br />
        panel.add(label);<br />
        JXLayer layer = new JXLayer(panel);<br />
        final LockableUI layerUI = new LockableUI() {<br />
            @Override<br />
            protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) {<br />
                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);<br />
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);<br />
                super.paintLayer(g2, l);<br />
            }<br />
        };<br />
        layer.setUI(layerUI);<br />
        JButton button = new JButton("Click Me");<br />
        button.addActionListener(new ActionListener() {<br />
            @Override<br />
            public void actionPerformed(ActionEvent e) {<br />
                layerUI.setLocked(!layerUI.isLocked());<br />
            }<br />
        });<br />
        JPanel mainPanel = new JPanel(new FlowLayout());<br />
        mainPanel.add(layer);<br />
        mainPanel.add(button);<br />
        add(mainPanel);<br />
        pack();<br />
        setLocationRelativeTo(null);<br />
        setVisible(true);<br />
        System.out.println(layerUI.isLocked());<br />
    }</p>
<p>    public static void main(String[] args) {<br />
        SwingUtilities.invokeLater(new Runnable() {<br />
            @Override<br />
            public void run() {<br />
                new JXLayerTest();<br />
            }<br />
        });<br />
    }<br />
}<br />