Display Image using ImageIcon and JLabel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Coreyja
    New Member
    • Nov 2008
    • 4

    #1

    Display Image using ImageIcon and JLabel

    Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get everything displayed how I want it to be. Here are the snippets of my code that I think are the important parts. Let me know if there is anything else needed to help me. Thanks in advance.

    Code:
    JLabel dice1 = new JLabel();
    ImageIcon one = new ImageIcon("dice/1.png");
    
    //set dice1 position
    dice1.setLocation(20, 100);
    dice1.setSize(115, 115);
    dice1.setIcon(one);
    gamepanel.add(dice1);
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Looks like it should work, what errors are you gettting?

    Comment

    • Coreyja
      New Member
      • Nov 2008
      • 4

      #3
      I wasn't getting any errors. I figured out that the problem was the path to the image. I was using the path from the java file but that wasn't where the path should have been from. Thanks for replying tho!

      Comment

      Working...