Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 937851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:32:38+00:00 2026-05-15T21:32:38+00:00

I want a JLabel with an Icon to look clicked, when mouse is clicked

  • 0

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 :)
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:32:39+00:00Added an answer on May 15, 2026 at 9:32 pm

    Assuming you read the image into from 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 would do the following:

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

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add at runtime a JLabel under the purple pane which contains
I want to create a dialog that contains some kind of text element (JLabel/JTextArea
I want to see the text of JLabel when I hover over the label.
I want to have an ImageIcon in a JLabel that i will be able
I want to recreate a table header looks using JLabel . The look and
Layout is FreeDesign I want to make less space between JLabel and JFrame in
How would I go about achieving the effect of JTextArea with JLabel? I want
I want to add some multiline text in a jlabel. I managed to do
I want to create a JLabel (containing an image) in the north position of
I want to copy my private jlabel object to a new jlabel object and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.