Go Premium for a chance to win a PS4. Enter to Win


How can I add Icon to JLabel Component

Posted on 2004-07-31
Medium Priority
Last Modified: 2011-09-20

Question by:moneymama
LVL 14

Accepted Solution

sudhakar_koundinya earned 200 total points
ID: 11685516
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

Author Comment

ID: 11685536
thanks for the quick response

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
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 …
Suggested Courses

972 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