package com.srbenoit.ui;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
/**
* A panel that simply presents an offscreen image. It is intended to be placed in a scroll pane.
*/
public class OffscreenImagePanel extends JPanel {
/** version number for serialization */
private static final long serialVersionUID = -8490317779957133123L;
/** the offscreen image to present */
private final transient BufferedImage offscreen;
/**
* Constructs a new OffscreenImagePanel
.
*
* @param image the buffered image to present.
*/
public OffscreenImagePanel(final BufferedImage image) {
super();
this.offscreen = image;
setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
}
/**
* Draws the image to the screen.
*
* @param grx the Graphics
object to draw to
*/
@Override public void paintComponent(final Graphics grx) {
grx.drawImage(this.offscreen, 0, 0, null);
}
}