Java BufferedImage Show showImage(String title, BufferedImage image)

Here you can find the source of showImage(String title, BufferedImage image)

Description

show Image

License

Apache License

Declaration

public static JFrame showImage(String title, BufferedImage image) 

Method Source Code


//package com.java2s;
/*/*  w  w  w .  j  av  a 2  s  .  com*/
 * Copyright 2005 Tom Gibara
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
    
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

import java.awt.Container;

import java.awt.Insets;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
    public static JFrame showImage(String title, BufferedImage image) {
        final JFrame f = new JFrame(title);
        Container pane = f.getContentPane();
        JButton display = new JButton(new ImageIcon(image));
        display.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                f.dispose();
            }
        });
        display.setMargin(new Insets(50, 50, 50, 50));
        pane.add(display);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.setVisible(true);
        return f;
    }
}

Related

  1. showImage(BufferedImage im)
  2. showImage(BufferedImage image, String title, boolean fitToScreen)
  3. showImage(BufferedImage img)
  4. showImage(BufferedImage img)
  5. showImage(final BufferedImage img, final HashMap inputHandles, final HashMap outputHandles)
  6. showImageLabel(BufferedImage imagen, JLabel jLabel, JComponent jc)