import java.awt.BorderLayout; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.border.LineBorder; public class BufferedImage2ImageIconClass { private static final long serialVersionUID = 1L; JPanel panel; JLabel label; ImageIcon icon; BufferedImage image; public BufferedImage2ImageIconClass() { File file = new File("/Users/joecze/Downloads/selbst.jpg"); try { this.image = ImageIO.read(file); } catch (IOException ex) { ex.printStackTrace(); } int imageBreite = image.getWidth(); int imageHoehe = image.getHeight(); icon = new ImageIcon(image); label = new JLabel(icon); label.setBorder(new LineBorder(Color.WHITE)); panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBackground(Color.DARK_GRAY); panel.add(label, BorderLayout.CENTER); JFrame frame = new JFrame("Image 2 ImageIcon"); frame.add(panel); frame.setSize(imageBreite + 100, imageHoehe + 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String args[]) { SwingUtilities.invokeLater(() -> new BufferedImage2ImageIconClass()); } }