Java: how to add image to Jlabel?
问题 Image image = GenerateImage.toImage(true); //this generates an image file JLabel thumb = new JLabel(); thumb.setIcon(image) 回答1: You have to supply to the JLabel an Icon implementation (i.e ImageIcon ). You can do it trough the setIcon method, as in your question, or through the JLabel constructor: Image image=GenerateImage.toImage(true); //this generates an image file ImageIcon icon = new ImageIcon(image); JLabel thumb = new JLabel(); thumb.setIcon(icon); I recommend you to read the Javadoc