Java Image displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey)

Here you can find the source of displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey)

Description

display Image

License

Apache License

Declaration

public static JDialog displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey) 

Method Source Code

//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;
    }
}

Related

  1. createShadowPicture(Image buf)
  2. createTiledImage(Image img, int width, int height)
  3. crop(Image source, int x1, int y1, int x2, int y2)
  4. displayImage(Image image)
  5. displayImage(Image img)
  6. divideImage(Object obj, int rows, int cols)
  7. ensureImageLoaded(Image img)
  8. findImagefromClasspath(Class relToThisClass, String relImageName)
  9. generateImageVisualizationPanel(String path, int width, int height, int scaling)