Here you can find the source of displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey)
public static JDialog displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey)
//package com.java2s; //License from project: Apache License import java.awt.BorderLayout; import java.awt.Image; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; public class Main { public static void displayImage(Image img, String mesg) { JDialog imgBox = displayImage(img, mesg, 100, 100, 500, 500); imgBox.setVisible(true);/* w w w . ja v a 2 s .c o m*/ } public static JDialog displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey) { JDialog imgBox = new JDialog(new java.awt.Frame(), mesg, false); JPanel imgPanel = new JPanel(new BorderLayout()); imgBox.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); imgBox.setLocation(locx, locy); imgBox.setSize(sizex, sizey); imgBox.setContentPane(imgPanel); ImageIcon imgIcon = new ImageIcon(img, ""); JLabel imgLabel = new JLabel(imgIcon); imgBox.add(imgLabel, BorderLayout.CENTER); return imgBox; } public static JDialog displayImage(URL resourcePath, String mesg, int locx, int locy, int sizex, int sizey) { JDialog imgBox = new JDialog(new java.awt.Frame(), mesg, true); JPanel imgPanel = new JPanel(new BorderLayout()); imgBox.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); imgBox.setLocation(locx, locy); imgBox.setSize(sizex, sizey); imgBox.setContentPane(imgPanel); ImageIcon imgIcon = new ImageIcon(resourcePath, mesg); JLabel imgLabel = new JLabel(imgIcon); imgBox.add(imgLabel, BorderLayout.CENTER); return imgBox; } }