Setting Custom Icons Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vman595
    New Member
    • May 2007
    • 7

    #1

    Setting Custom Icons Help

    Hey guys,

    I writing a program (major project actually ^^ ) and I need to set a icon (using a label) to a custom picture / path. I'm having trouble, although the IDE (I'm using NetBeans btw) doesn't show errors, it doesn't display the picture either.

    Here is my code:

    public void setOverview(Str ing name)
    {
    ImageIcon pic = new ImageIcon("/YachtPackage/"+name+".jp g");
    boatOverviewLbl .setIcon(pic);
    }

    Thanks in advance!
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by vman595
    Hey guys,

    I writing a program (major project actually ^^ ) and I need to set a icon (using a label) to a custom picture / path. I'm having trouble, although the IDE (I'm using NetBeans btw) doesn't show errors, it doesn't display the picture either.

    Here is my code:

    public void setOverview(Str ing name)
    {
    ImageIcon pic = new ImageIcon("/YachtPackage/"+name+".jp g");
    boatOverviewLbl .setIcon(pic);
    }

    Thanks in advance!
    Are you sure your icon is stored in the directory /YachtPackage and are you
    sure the extension of the file name is .jpg? It surprises me a bit that the
    YachtPackage is stored right under the root directory ...

    kind regards,

    Jos

    Comment

    • vman595
      New Member
      • May 2007
      • 7

      #3
      Found solution:

      public void setOverview(Str ing name)
      {
      boatOverviewLbl .setIcon(new javax.swing.Ima geIcon(getClass ().getResource( "/YachtPackage/Overviews/"+name+".jpg")) );
      }

      Thanks anyway.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by vman595
        Found solution:

        public void setOverview(Str ing name)
        {
        boatOverviewLbl .setIcon(new javax.swing.Ima geIcon(getClass ().getResource( "/YachtPackage/Overviews/"+name+".jpg")) );
        }

        Thanks anyway.
        I find it a bit strange that this variant indeed does work while the previous
        version doesn't.

        kind regards,

        Jos

        Comment

        • vman595
          New Member
          • May 2007
          • 7

          #5
          Well one of the problems was my path (silly me :P) that and I checked out the NetBeans generated code and used that to help me.

          Comment

          Working...