What is the best way to do icon overlay in Java?

Posted on 2011-03-16
Last Modified: 2012-05-11

What is the best way to do icon overlay in Java?

Question by:jamie_lynn
  • 2
LVL 47

Expert Comment

ID: 35153173
What do you mean by icon overlay?
Are you talking about some visual lement, like JList, JTable, or something else?
Please, be a little bit more specific.

Accepted Solution

jamie_lynn earned 0 total points
ID: 35153733
Hi for_yan,

I meant 2 icon images displayed, one overlayed ontop of the other.
Like an "x" on top of a connection icon, if the connection is broken.

But i found the solution.


Author Closing Comment

ID: 35178878
public class OverlayIcon extends ImageIcon
private ImageIcon base;
private List overlays;

public OverlayIcon(ImageIcon base)
this.base = base;
this.overlays = new ArrayList();

public void add(ImageIcon overlay)

public synchronized void paintIcon(Component c, Graphics g, int x, int y)
base.paintIcon(c, g, x, y);
for(ImageIcon icon: overlays)
icon.paintIcon(c, g, x, y);

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now