Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: Displaying image in JPanel
|
Posted: Jun 25, 2002 4:11 PM
|
|
import java.awt.*; import java.io.*; import javax.swing.*;
public class ImagePanel extends JPanel{ private ImageIcon imageIcon; public ImagePanel(File imageFile){ super(); imageIcon = new ImageIcon(imageFile.getAbsolutePath()); setPreferredSize(new Dimension(imageIcon.getIconWidth(), imageIcon.getIconHeight())); } public ImagePanel(String imageFileName){ super(); imageIcon = new ImageIcon(imageFileName); setPreferredSize(new Dimension(imageIcon.getIconWidth(), imageIcon.getIconHeight())); } public void paint(Graphics g){ super.paintComponent(g); g.drawImage(imageIcon.getImage(),0,0,this); } }
|
|