Search code examples
javaimageswingjframejlabel

Add images to a jframe


I keep trying all this example code and none of it works, it always wants me to have a try/catch which means I have to ini. the variable anyway and I am tearing my hair out on the one, I have a jframe the exact size of my image, all I want is it to fill the entire jframe, also, could you make it so that if the image is transparent, that you can see though the entire jframe.

Thanks in advance


Solution

  • frame.add(new JLabel(new ImageIcon("path/to/image.png"));
    

    There is a class called ImageIcon that can be used for images in Swing. Javadocs for ImageIcon

    There are also many other ways to use ImageIcon.