What would be the most appropriate image type to display a jpg image (loaded from a local folder) on a JPanel?
Cheers.
What would be the most appropriate image type to display a jpg image (loaded from a local folder) on a JPanel?
Cheers.
You could use a javax.swing.ImageIcon and add it to a JLabel using setIcon() method, then add the JLabel to the JPanel.
ImageIcon image = new ImageIcon("image/pic1.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
I would use a Canvas that I add to the JPanel, and draw the image on the Canvas. But Canvas is a quite heavy object, sine it is from awt.