|
-
September 21st, 2000, 07:25 PM
#1
JPanel and Images
How does one add an image (gif file) to a JPanel?
Thanks much!
-
September 21st, 2000, 11:38 PM
#2
Re: JPanel and Images
Hi Lisa
Probably the easiest way to do this
is by putting the image inside a JLabel and
then adding it, like the following example:
--------------------------------
import javax.swing.*;
import java.awt.event.*;
class ShowImageFile extends JFrame{
JPanel jay;
JLabel jl;
public static void main(String[] args){
new ShowImageFile();
}
public ShowImageFile(){
setSize(500,500);
jay = new JPanel();
jl = new JLabel(new ImageIcon("TenPeople.jpg"));
jay.add(jl);
getContentPane().add(jay);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
Gif will work fine also.
Phill.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|