Question:

How to add picture on a frame in java??help?

by  |  earlier

0 LIKES UnLike

i want to add pic on a frame created by me in java....how can i do that

help plzz

 Tags:

   Report

2 ANSWERS


  1. If the image is an in-memory Image object or stored in a file in JPEG, GIF, or PNG format, then just create an ImageIcon and display it as the content of a JLabel.  Then put the JLabel in the content pane of your JFrame.

    public class PictureFrame extends JFrame{

    public PictureFrame(String pictureFile){

    super("Picture Frame");

    Icon icon = new ImageIcon(pictureFile);

    JLabel label = new JLabel(icon);

    getContentPane().add(label);

    }

    //pass path name to image file as a command line argument

    public static void main(String[] args){

    JFrame f = new PictureFrame(args[0]);

    f.setDefaultCloseOperation(JFrame.EXIT...

    f.pack();

    f.setVisible(true);

    }

    }


  2. SEARCH IT ON GOOGLE

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions