I want a JLabel with an Icon to look “clicked”, when mouse is clicked on the Label. The Label contains an ImageIcon. Instead of changing the icon to another one, I want to redraw the ImageIcon with another colorset (e.g.: setXORMode(new Color(255,0,0) ) “on the fly”. Anyone has a hint how to manage that?
JLabel my_label = new JLabel("");
my_label.setIcon(new ImageIcon(MyClass.class.getResource("/path/to/resources/myicon.jpg")));
my_label.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
//HERE I NEED THE VODOO :)
}
});
Assuming you read the image into from disk you would do something like this.
Later when you need to change XOrMode you would do the following:
If you want to fadein/fadeout, I’d recommend the timing framework. Also, if you want to repaint the part of the label itself in addition to the image in the label, you can override
void paintComponent(Graphics g).A very good resource for that you might consider looking into is the book Filthy Rich Clients. It’s full of this kind of stuff. If you look the examples on the website from Chapter 4 there is some sample image code that might be useful. It would be a very, very good book for you to pick up too.