Fade / Redraw / Modify ImageIcon when clicking on SWING JLabel on the fly

I want the JLabel with the icon to look “clicked” when the mouse is clicked on the shortcut. The shortcut contains ImageIcon. Instead of changing the icon to another, I want to redraw ImageIcon with a different set of colors (for example: setXORMode (new color (255,0,0)) “on the fly.” Does anyone have a clue how to do this?

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 :)
    }
});
+3
source share
2 answers

Assuming you are reading an image from a disk, you would do something like this.

URL url = getClass().getResource("images/BB.jpg");
BufferedImage picture = ImageIO.read(url);

Later, when you need to change XOrMode, you must do the following:

Graphics2D g = picture.createGraphics();
g.setXORMode(new Color(255,0,0) )
g.dispose();

fadein/fadeout, . , , void paintComponent(Graphics g).

, , - Filthy Rich . . - 4, . , .

+2

LookupOp, . setIcon() .

+2

Source: https://habr.com/ru/post/1755120/


All Articles