How can I add Icon to JLabel Component

Who is Participating?

Improve company productivity with a Business Account.Sign Up

sudhakar_koundinyaConnect With a Mentor Commented:
You need some thing like this

    // Fetch icon
    Icon icon = new ImageIcon("icon.gif");
    // Create a label with text and an icon; the icon appears to the left of the text
    JLabel label = new JLabel("Text Label", icon, JLabel.CENTER);
    // Create a label with only an icon
    label = new JLabel(icon);

This example adds or replaces the icon in an existing JLabel component:

    // Add an icon to an existing label
moneymamaAuthor Commented:
thanks for the quick response
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.