JLabel Icon error

Hello to everyone,
I've recently tried to add a photo on JLabel within my project.. I opened a package for images, and I just linked then in JLabel properties -> Icon section.. But it gives an exception like "*Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException*
*at javax.swing.ImageIcon.<init>(ImageIcon.java:167)*"
. I googled it; some of webs say it is a bug.. I don't have any other things except a jlabel, and photos.. When I tried to add photo from a direct path; there's no problem; but I want to add it in project; because I'll make it a jar archive.. So they(images) have to be in project folder... Again, I didn't write any codes.. Just used GUI to add photo..
Thanx for advance..
With regards..

If you don't want to help, you don't have to replyYes we do have to reply because this is not the proper place to ask the question. Learn how to use the forums properly.
Anyway We can't help because you don't know how to ask a question.
Your question is referring to some code that was generated by an IDE. We have no idea what IDE you are talking about.
This is not a forum for answering IDE questions. So go to your IDE forum and ask a question.
Or learn how to write the code yourself and then you can post a question on the Java Swing forum.
Start by reading the Swing tutorial on "How to Use Icons".

Similar Messages

  • JLabel (icon Image) without picture?

    I am make applet containing JLabel (Icon Image). When I run this applet from server and used image-file "middle.gif" (from tutorial) - there was all Ok. After this I changed color of image on MS Photo Editor and now I get JLabel without icon and there is no errors. I don't understand what happens? Anybody know what is it?

    Of course. In directory "Images" I have follow files:
    green.gif
    middle.gif
    red.gif
    Files green.gif and red.gif are middle.gif but pictures on them have respective colors. This colors I get using MS Photo Editor.
    import javax.swing.*;
    import java.awt.*;
    import java.net.*;
    public class tLabImage extends JApplet{
    public void init () {
    JFrame f=new JFrame();
    URL url=null;
    try {
    // url=new URL("http://10.1.1.6/Images/middle-1.gif");
    url=new URL("http://10.1.1.6/Images/green.gif");
    catch (MalformedURLException e) {System.out.println (e.getMessage());}
    Image image=getImage(url);
    ImageIcon icon=new ImageIcon(image);
    JLabel l=new JLabel ("text", icon, JLabel.LEFT);
    f.setLocation(200,300);
    f.getContentPane().setLayout(new GridLayout(0,2));
    f.getContentPane().add(l);
    f.pack();
    f.setVisible(true);
    When I run this programm I get JLabel without icon (only text). Why? Who can answer?

  • Unknown "Sad iPod Icon" Error With No Resolution I can Find

    I have a Third Generation iPod 40GB
    I was camping and during my camping trip my ipod froze and I was forced to reset it. (Holding Menu and Select for a few seconds)
    The Apple Icon showed as normal but then I got the "Exclamation Point Folder Icon" Error and I had never seen this before so I left my ipod alone.
    Later that night I wanted to check the time and turned on my iPod without thinking the main menu came up instead of the previous error but once I realized it was alright I was over joyed and proceeded to test my music I played my first playlist and it started to rapidly skip through the songs it would show the title pause for a split second and error to the next song... I tried to stop the song and the iPod Locked up and I was again forced to reset it this time i got the "Sad Ipod Icon" error In an Endless loop of showing the Error Then retting the Ipod causing its harddrive to run for about four seconds then stop and start endlessly.
    I got home and researched the problem learning I'd have to Restore my Ipod, It wouldn't connect in its current Error Loop State so I went through the Motions to put the Ipod into Disc Mode so I can connect it...it worked like a charm that far but when i plugged my Ipod into my computer (I run the firewire cable as my USB ports are Only USB1)
    after about 30 seconds of being connected I heard the trademark sound showing it was connected then the Ipod Reset itself Showing the Apple Icon again and Ending the connection before I can Restore my iPod
    I've Tried this 5 times and used a diffrent computer to try and reformate the Ipod Using Internal Windows Reformatting In Windows XP Still no Luck
    I've Completely Run out of Ideas and Have Googled my problem 100 diffrent ways none of them coming up with anything like this problem Can someone Please Help me.
    A1059   Windows XP   Third Generation 40GB

    Alright I fixed it and heres how it went...I tried a 100th time to connect via USB and this time being frustrated i gave my ipod another smack...it knocked it out of the loop it was in and it connected to the computer... and the Ipod was recognized but corrupt I then got it to show in the restorer and Restored it to factory condition but it still couldn't show up in Itunes but it showed in windows explorer so I then went to the iPod troubleshooting section about that and went thru there instructions to get it to recognized and after some of that I used there instructions to rebuild the "Control" folder on the ipod and it worked perfectly and it showed up and I'm as we speak i'm uploading music this is gonna take a while!

  • JLabel Icon Updates

    I am running a MYSQL query and assigning the values to Jlabels. Like this:
    jLabel2.setText ( nameVal );I want to be able to assign the icons of the jLabels as well. Is this possible?

    Same result. Here is the whole thing right from the tutorials:
    //package components;
    import java.awt.GridLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    import javax.swing.UIManager;
    import javax.swing.SwingUtilities;
    * LabelDemo.java needs one other file:
    *   images/middle.gif
    public class LabelDemo extends JPanel {
        public LabelDemo() {
            super(new GridLayout(3,1));  //3 rows, 1 column
            JLabel label1, label2, label3;
            ImageIcon icon = createImageIcon("http://duke.kenai.com/iconSized/duke4.gif",
                                             "a pretty but meaningless splat");
            //Create the first label.
            label1 = new JLabel("Image and Text",
                                icon,
                                JLabel.CENTER);
            //Set the position of its text, relative to its icon:
            label1.setVerticalTextPosition(JLabel.BOTTOM);
            label1.setHorizontalTextPosition(JLabel.CENTER);
            //Create the other labels.
            label2 = new JLabel("Text-Only Label");
            label3 = new JLabel(icon);
            //Create tool tips, for the heck of it.
            label1.setToolTipText("A label containing both image and text");
            label2.setToolTipText("A label containing only text");
            label3.setToolTipText("A label containing only an image");
            //Add the labels.
            add(label1);
            add(label2);
            add(label3);
        /** Returns an ImageIcon, or null if the path was invalid. */
        protected static ImageIcon createImageIcon(String URL,
                                                   String description) {
            java.net.URL imgURL = LabelDemo.class.getResource(URL);
            if (imgURL != null) {
                return new ImageIcon(imgURL, description);
            } else {
                System.err.println("Couldn't find file: " + URL);
                return null;
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event dispatch thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("LabelDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Add content to the window.
            frame.add(new LabelDemo());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event dispatch thread:
            //creating and showing this application's GUI.
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
              //Turn off metal's use of bold fonts
                 UIManager.put("swing.boldMetal", Boolean.FALSE);
              createAndShowGUI();
    }

  • Word 2013 (Windows 7 64-bit) - Embed PDF as Icon Error

    We have a process where we embed PDFs into a table in a Word document as an icon.
    This worked for us in Word 2010, but as soon as we upgraded to Word 2013 we started getting an error message.
    "The program used to create this object is Package.  That program is either not installed on your computer or it is not responding.  To edit this object, install Package or ensure that any dialog boxes in Package are closed."
    Nothing has changed except uninstalling Office 2010 and installing Office 2013.  Acrobat is still there(fully updated XI pro). Acrobat is not open when the attempt to embed is made.
    I've tried altering every option I could find that might make this process work, but nothing does the trick.  All software is fully updated as far as I can tell.   It feels like Office 2013 is not keen on the idea of working with PDFs.  The
    Acrobat Add-In seems to only promote converting word docs to PDFs, and I found little to no settings referring to PDF embedding or any embedding for that matter.
    Does Word 2013 disallow this feature unless you're using Windows 8 and the Windows Reader app?  
    Any advice would be fantastic.  Thanks.

    Hi,
    Please try to insert some PDF files from  Insert tab --> Object --> Create New --> Adobe Acrobat Document
    In addition, make sure Adobe Reader is the default application to open the PDF files.
    If the issue persists, please try repair or reinstall the latest version of Adobe reader and check this again.
    Karen Hu
    TechNet Community Support

  • Download image preview icon error

    I have a pacbook pro(mid 2012) purchase os maverick 500 gb  and ram 4gb. free space is 160gb.
    if i download an image from internet to my desktop. the image thumbnail shows downloading. I have attached a screenshot too. if i press spacebar it shows a preview error. if i double click it to preview the image opens. but the desktop icon remains the same. This is happening with 50% of the images i download to desktop.
    Please help.

    The same thing appears to be a latent bug from Tiger -- I am seeing this in 10.4.11, and as Rob notes, it's not always consistent.
    What's worse, Rob's suggestion won't work for me... because the "Select New Original..." button is greyed out! I realize this is technically a Leopard thread, but I can't imagine this was deliberately changed between 10.4 and 10.5, so I would think it would be applicable pretty broadly.
    Any ideas or suggestions would be very welcome indeed.
    Thanks,
    /H

  • Simulating animation by iterating - JLabel icon. ONLY  Working first time!

    I am "simualting" animation by changing the icon attribute of a JLabel. If I call the method from main, this works. It also seems to work (ie. the JLabel image changes on the screen as the icon attribute is changed in the program.) if I call it first from another or its own class one time, but not after that. What happens on subsequent calls is: The thread.sleep() is working (time passes), and the icon attribute of the JLabel is chaging (lblCaveActive.getIcon() for the JLabel returns the correct changed *.gif, but the images do not show up on the screen, until the last image, whatever I set it to be. I am pulling my air out over this little problem, which is the last lingering problem I am having with this project....I was wondering if you have seen this or have any ideas? I have tried lots of different things, including repainting and such. If you have a clue concerning this, please please please advise, o wise one.
    * simulates animation: ex. Wumpus approaching to eat the
    * player, bat appraoching to transport player
    * @param: int numPics - number of pictures to loop through
    * @param: String picNamePreface - filenames must be "*0.gif" through
    * picNamePreface + numPics + ".gif".
    * Send the "*" portion into this arg
    * @param: int milliSecSleep - seconds for the thread to sleep between
    * pictures
    private void animateMeetHazard(int numPics, String picNamePreface,
    int milliSecSleep)
    try
    for (int i = 0; i <= numPics; i++)
    caveCurrentIcon = new ImageIcon(picNamePreface + i + ".gif");
    lblCaveActive.setIcon(caveCurrentIcon);
    Thread.sleep(milliSecSleep);
    catch (InterruptedException e){}
    --A very tired girl.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Something like
    private void animateMeetHazard(int numPics, String picNamePreface,
    int milliSecSleep)
    try
    SwingWorker workHard = new SwingWorker()
    public Object construct()
    for (int i = 0; i <= numPics; i++)
    caveCurrentIcon = new ImageIcon(picNamePreface + i + ".gif");
    lblCaveActive.setIcon(caveCurrentIcon);
    Thread.sleep(milliSecSleep);
    return null;
    public void finished()
    workHard.start();
    catch (InterruptedException e){}
    Not really sure if the Thread.sleep() will throw you out and give you the same problems .. but it mightn't ;)

  • Cant change JLabel icon with setIcon a second time???

    Hey all,
    I have drawn 21 cards on my GUI - then as a user selects one of three columns via a radio button and subsequent Submit button, the deck reshuffles itself, and is THEN supposed to change all the labels to the new cards in their New order.
    All the code is good up until the point where it tries to reset the icon - and then I get a
    "AWT-EventQueue-0" java.lang.NullPointerException
    pointing to the line of my first Label that I am changing.
    I am trying to use the same settings as I did in the initial setting and think that maybe this could be my problem, but cannot find a proper setting in the Interface.
    My initial settings are this :
    for (i=0; i < 7; i++)
              cardscol1.setIcon(new ImageIcon("images\\" + deck.get(i)));
    cardscol2[i].setIcon(new ImageIcon("images\\" + deck.get(i + 7)));
    cardscol3[i].setIcon(new ImageIcon("images\\" + deck.get(i + 14)));
    THEN I tried this again (( INSIDE MY buttonHandler ))
    for (i=0; i < 7; i++)
                            j=0;
                            cardscol1.setIcon(new ImageIcon("images\\" + deck.get(j)));
    j++;
    cardscol2[i].setIcon(new ImageIcon("images\\" + deck.get(j)));
    j++;
    cardscol3[i].setIcon(new ImageIcon("images\\" + deck.get(j)));
    j++;
    And this is where I get the NULL POINTER EXCEPTION -- help??
    ****UPDATE:
    I cant access these Label PERIOD from within my Button Handler -- any idea why?

    OK -- the cardscol1 and 2 and 3 JLABEL arrays reference cards11, 12, 13, 14, etc. etc... THESE CARDS are within the initComponents class that is in a seperate class as well -- so that is probably my problem-- how do I get this submitButtonHandler class to see the cards that are in my initComponents class???
    AND THIS initComponents class is listed as PRIVATE!!! ((This is a class that the NetBeans GUI maker sets up -- very nice feature, but I cannot edit this class at all!))
    Message was edited by:
    tvance929

  • Fusion-icon error: glxinfo not installed. [SOLVED]

    Hi,  I am running gnome at the moment and I am trying to get compiz and emerald started.  I type into the terminal:
    [semperfiguy: ~]$ fusion-icon
    * Detected Session: gnome
    * execution of "which glxinfo" failed
    * Error: glxinfo not installed!
    And I get that error.  Now when I run glxinfo from the it spits out a whole bunch of stuff.  So it is obviously installed correct?  So why is it giving me this problem?
    Last edited by semperfiguy (2008-06-17 15:20:04)

    This is what I get:
    [semperfiguy: ~]$ which glxinfo
    bash: which: command not found
    Installed "which" and it works fine.. thank you!

  • Putting JLabel icon images in .jar

    I'm trying to make my program display JLabels with icons. This works successfully, however it relies on local files. I want to distribute the jar file only, so I was hoping there was a way I could put the images in the package or subfolder within the jar file and have the code reference the pictures there. Is there a way to do this. The code I'm using now is as follows :
    if(status.equals("good")){
         return (new JLabel(new ImageIcon("images/OK.gif")));
    }else //if(status.equals("bad"))
    return (new JLabel(new ImageIcon("images/FAIL.gif")));
    Thanks for any advice you my have.

    Putting both the class files and the images files in the same jar definitely works.
    I do it all the time. The simplest thing to do is to put the images in the same folder
    as the class file that accesses them, then jar up the lot. Your code should look like:
    URL url = this.getClass().getResource("your_image.jpeg");
    Icon icon = new ImageIcon(url);
    //etc...In fact, you should always code in this way: this code works will a jarred or unjarred program.
    Because with file names, however: jar file names are always case sensitive.

  • JLabel Icon Update Question

    Hi. I have created a jLabel that get's it's Icon updated via a value derived from a MYSQL query. The Icon1 value is a URL. My question is, if I do the MYSQL query and the URL doesn't change from the existing value, does the jLabel still go out and pull the image over? Or does it recognize that the URL is still the same and doesn't make an attempt at pulling the image over? Basically, I am asking this because I'm trying to determine the load on my webserver. Thank you for your help!
    image1.setIcon(icon1);

    Hi Daryl. Here is what I'm doing:
    protected static ImageIcon createImageIcon(String URL,
                                                   String description) {
            //java.net.URL imgURL = LabelDemo.class.getResource(URL);
            java.net.URL imgURL = null;
        try {
          imgURL = new java.net.URL(URL);
        } catch (Exception e) {
          //Logger.getLogger(LabelDemo.class.getName()).log(Level.SEVERE, null, ex);
            if (imgURL != null) {
                return new ImageIcon(imgURL, description);
            } else {
                System.err.println("Couldn't find file: " + URL);
                return null;
    ImageIcon icon1 = createImageIcon("https://www.website.com/images/" + dateVal + "/thumbs/" + image2Val + "",
                       image1.setIcon(icon1);

  • Adding a wiki icon = error

    Hi,
    Just set up my Snow Leopard Server and am trying to add a Wiki icon via the web interface. Does not matter what computer I am on, when I select any type of image, JPEG, PNG, TIFF, doesn't matter. I get an error message.
    "https://ljeproductions.com
    There was an error uploading the file. Please try again."
    Anyone have a suggestion of what I can do to fix this? It happens on any wiki I create so I'm thinking it may be a permission issue or a setting thats wrong.

    Hi, try repairing your permissions in Disk Utility. You can also ensure that you have permissions on the location of the stored website directory.

  • JLabel Icon Size

    Hi,
    I wanted to use an image as a background for my JPanel. I didn't want to fuddle around with custom painting so I just created a Jlabel with an icon, and added that to the panel. My problem is that, the icon is always the same size, no matter the size of the label. Any extra space just gets filled with the getBackground() color. How can I adjust the icon's size inside the JLabel?
    Thanks a lot!

    Check out these threads:
    [url http://forum.java.sun.com/thread.jsp?forum=31&thread=286424&start=3&range=1]Painting an Image.
    [url http://forum.java.sun.com/thread.jsp?forum=57&thread=417669&start=2]Scaling an Image.

  • JLabel Icon from online image?

    I am writing a program (purely for curiosity-sake) that searches the automotive section of a popular online classifieds website, retrieves the 20 latest ad posts (the 20 newest cars posted), and displays the title ("1969 Mustang, great shape! Must sell!", etc.), price, description, and post time/date in labels in my program (using Swing). This all works fine so far, but one feature I would like to implement is causing me some grief. Each online posting has a thumbnail image which I would like to retrieve and display in my program. I would like to use a JLabel, then set the "icon" property to reference the online image. I don't wish to have hundreds of thumbnails caches in programs' project folder, so is there a way to set the label's icon property to not only an external image, but an online one? I am using NetBeans 6.0.1 and JDK1.6.0_03. In NetBeans, using the Properties window on the right, the "icon" property allows me to choose an external, but local, image -- this doesn't help much. All online thumbnails are the same size (64x48), and my label is the same size (it will be strictly an image displayer, no text). Any help greatly appreciated!

    ImageIO could load from the URL of the image of your interest.

  • JLabel icon position question

    I want to have a JLabel with text and an icon. I want the text to be positioned on the left and I want the icon on the right. My question is: Is this possible and if so how?

    RTFM
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JLabel.html#setHorizontalTextPosition(int)

Maybe you are looking for

  • How can I define a default character enconding for Firefox 4?

    Dear Sirs, I would like to know how can I change the character encoding of Firefox 4 to Western (ISO-8859-1) and keep that character enconding as the default every time I open Firefox 4. I have noticed the every time I change the default character en

  • How do i get rid of Adware/malware on my Macbook Pro?

    I have a MacBook Pro, 15" with Retina Display, When i click on a page, mackeeper opens up in a new tab, also my default browser which is "Google.com" has been changed to "Search-Quick.com". i also just started seeing a pop up Ad, also from the "macke

  • Failing 10.2.3.2 audit vault patch on AV Agent at AV Configuation Assistant

    Hi, Applying 10.2.3.2 audit vault patch on top of 10.2.3.0 Audit Vault Agent. Getting following error after 100% installation at the time of Audit Vault Configuation Assistant Components Information from Installxxxxxx.log OPatch succeeded. INFO: Conf

  • Logical Key for Degenerate Dimension

    Hi Gurus, Need some help on the degenerate dimensions in the BMM layer. I have one fact table with dimension attributes and I would like to move the attributes into separate logical table and treat it as dimension. Now my newly created dimension has

  • Pop up windows are not scrollable?

    I have noticed that comparing to other browsers when there's a popup window, for example when using PrintFriendly to print the page I'm visiting - that popup window is not scrollable at all, making it impossible to decide what to print or not. Let me