In short, with this technique, you create an
ImageIcon with the image you want to display, and then add the
ImageIcon to your
JLabel constructor. After you put the
ImageIcon on the
JLabel, you can display the
JLabel wherever you want, and your image will be displayed.
Here's my Java
JLabel example code:
ImageIcon myImage = ImageIcon(com.devdaily.myapp.MainFrame.class.getResource("openFile.png")); // Somewhere later in the code ... JLabel myLabel = new JLabel(); jmyLabel.setIcon(myImage);
There are certainly other Java image approaches, and I share many of those on this blog, but I've used this Java image display technique many times.