Re: How to make Image size as the label has?
- From: "Bart Cremers" <bcremers@xxxxxxxxx>
- Date: 23 Feb 2006 00:20:07 -0800
import javax.swing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* @author Bart Cremers
* @since Feb 23, 2006
*/
public class JImageFrame extends JFrame {
public JImageFrame(Image image) {
setContentPane(new ImagePanel(image));
}
public static void main(String[] args) throws IOException {
String pic = "somePic.jpg";
BufferedImage img = ImageIO.read(new File(pic));
JFrame f = new JImageFrame(img);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
}
private class ImagePanel extends JPanel {
private Image image;
public ImagePanel(Image image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}
}
.
- Follow-Ups:
- Re: How to make Image size as the label has?
- From: Manoj Jain
- Re: How to make Image size as the label has?
- References:
- How to make Image size as the label has?
- From: Manoj Jain
- How to make Image size as the label has?
- Prev by Date: How to make Image size as the label has?
- Next by Date: Re: Jpanel Takes Time To Draw Image (late)
- Previous by thread: How to make Image size as the label has?
- Next by thread: Re: How to make Image size as the label has?
- Index(es):