Here you can find the source of generateImageVisualizationPanel(String path, int width, int height, int scaling)
public static JPanel generateImageVisualizationPanel(String path, int width, int height, int scaling)
//package com.java2s; //License from project: Open Source License import java.awt.BorderLayout; import java.awt.Color; import java.awt.Image; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; public class Main { public static JPanel generateImageVisualizationPanel(String path, int width, int height, int scaling) { JPanel panel = new JPanel(new BorderLayout()); try {//from ww w . j a va 2 s. co m Image image = ImageIO.read(new File(path)); // Read from an input stream InputStream is = new BufferedInputStream(new FileInputStream(path)); image = ImageIO.read(is); ImageIcon icon = new ImageIcon(path); // icon.setImage(icon.getImage().getScaledInstance(width, height, scaling)); icon.setImage(image); JLabel label = new JLabel(icon); panel.setBackground(Color.white); panel.add(label, BorderLayout.CENTER); } catch (Exception e) { e.printStackTrace(); } return panel; } }