How can i display a JPG image in a JFrame ?

sample code would be appreciated
marvinrouge

Thanks both : it helped
here is the code given to all jana-net-guys
it displays from 1.jpg to 12.jpg
how can i improve it to displays all .jpg and .gif even if their names ARE NOT like <number>.jpg ???
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class PhotoDisplayer extends JFrame implements ActionListener {
     JPanel cp = new JPanel();
     public PhotoDisplayer() {
          getContentPane().setLayout(new BorderLayout());
          setImage(1);
               cp.add(first);
               first.addActionListener(this);
               cp.add(prev);
               prev.addActionListener(this);
               cp.add(next);
               next.addActionListener(this);
               cp.add(last);
               last.addActionListener(this);
               cp.add(exit);
               exit.addActionListener(this);
          getContentPane().add(cp, BorderLayout.SOUTH);
          pack();
          show();
     public void setImage(String image) {
          ImageIcon ii = new ImageIcon(image);
          if (ii.getIconHeight()>height)
               height = ii.getIconHeight();
          if (ii.getIconWidth()>width)
               width = ii.getIconWidth();
          JLabel img = new JLabel(ii);
          JScrollPane sp = new JScrollPane(img);
          getContentPane().removeAll();
          getContentPane().add(sp, BorderLayout.CENTER);
          getContentPane().add(cp, BorderLayout.SOUTH);
          setTitle(image);
          pack();
     public void setImage(int img) {
          setImage("" + img + ".jpg");
     public int image = 1;
     public void moveImage(int dec) {
          if (image+dec>=1 && image+dec<=12) {
               image += dec;
               setImage(image);
     public void actionPerformed(ActionEvent event) {
          if (event.getSource()==first)
               setImage(1);
          if (event.getSource()==prev)
               moveImage(-1);
          if (event.getSource()==next)
               moveImage(1);
          if (event.getSource()==last)
               setImage(12);
          if (event.getSource()==exit)
               System.exit(0);
     int width = 320;
     int height = 200;
     JButton first = new JButton("First");
     JButton prev = new JButton("Prev");
     JButton next = new JButton("Next");
     JButton last = new JButton("Last");
     JButton exit = new JButton("Exit");
     public static void main(String[] args) {
          new PhotoDisplayer();
     public Dimension getPreferredSize() {
          return new Dimension(width, height);
}

Similar Messages

  • How can I display a JPG Date Taken stamp on images?

    I have several digital JPG images taken that I would like to pull EXIF data from to display a timestamp on the photo.  I know many old cameras used to do this natively, but my iPhone does not imprint the date and time on the images.  I want to pull the data from the JPG so it will display the correct info on the image for when the picture was taken.  Any help is appreciated.  I own Adobe Web Premium CS5.
    Thanks, Bryan

    If the EXIF metadata is in the jpeg you can do what you want using a photoshop script retrieve the date and time in matadata and add a text layer containing a timestamp. Here is an example where more then just the timestamp was stamped onto an image. http://www.mouseprints.net/old/dpr/StampExif.jsx

  • How Can I Display Remote Mail Images

    I set my iPhone 3G (iOS4) to NOT automatically load remote image as a means of preventing advertising to spammers that I exist. However, there are notes I receive that I would like to view the remote images - i.e. from my bank, broker and other subscribed to newsletters.
    However, once I turn "automatically load remote images" to off, there seems to be no way to manually load remote images ad-hoc. Am I wrong or have I missed something in the manual? IF there is a way to manually display remote images, can someone tell me how?
    Any help or suggestions would be appreciated.
    TIA

    Sorry I know this is an old thread but thought I would let you know what I have found as I too have been trying to find this out and stumbled across some other threads.
    Looks like this feature is missing and people have been on the case for a few years now! I found some old threads from early 2009, someone even got in contact with apple and the support team didn't know either. So in short even though the manual does indeed say that you can load remote images manually when you have the load remote images setting to off, it looks like we still can't. I am using iOS 4.2.1 and still can't find anywhere where we could load them manually.
    So I found in another thread someone said to send in feedback forms to apple using this link:
    http://www.apple.com/feedback/iphone.html
    I thought this might be a good idea?

  • How can I Display a Image with tiff format in Jpanel?

    How can I Display a CMYK Image with tiff format in Jpanel ? Not in ScrollingImagePanel? Thank you in advance.

    Why nobody can help me?I am very anxious!help me,please!

  • Why can't I resize jpg images in the applet?

    I used this code to display images in an html page. One applet for one image. But out of the 8 images I loaded, 6 adjusted themselves to 320x240 automatically, 1 randomly jumps around to certain parts of the image every 250millisecs, and 1 just cuts the top left hand part of 320x240. How can .jpg files give 3 different situations? I tried using the resize() method in the code but it doesn't do anything! How can I size those .jpg images to the size I want?
    /**This video stream applet loads a new image every 250ms
    import java.applet.*;
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.awt.event.*;
    public class Video extends Applet implements Runnable{
    private Image img,buffer;
    private Thread video = null;
    private URL url;
    private MediaTracker tracker;
    public synchronized void init(){
    tracker = new MediaTracker(this);
    try{url = new URL(getCodeBase(),"Camera1.jpg");}
    catch(MalformedURLException e){}
    img = getImage(url);
    tracker.addImage(img, 0);
    buffer = createImage(320,240);
    resize(320,240);
    if(video!=null)return;
    video = new Thread(this,"VideoStream");
    video.start();
    public synchronized void destroy(){
    if(video!=null)video=null;
    public void run(){
    while(!Thread.interrupted()){
    // Load new image.
    try{tracker.waitForID(0);}
    catch(InterruptedException e){}
    // Draw new Image.
    repaint();
    // Remove old image & add new one.
    tracker.removeImage(img,0);
    img.flush();
    tracker.addImage(img,0);
    // Sleep
    try{Thread.sleep(250);}
    catch(InterruptedException e){}
    public synchronized void update(Graphics g){
    Graphics bufGraph = buffer.getGraphics();
    bufGraph.drawImage(img,0,0,this);
    paint(bufGraph);
    g.drawImage(buffer,0,0,this);
    public void paint(Graphics g){
    g.drawImage(buffer,0,0,this);
    Also how can I add more than 1 .jpg in an applet since the applet tag for html is
    <applet code = Video.class width =... height = ...>
    <param name = "buffer" value = "Camera1.jpg"> ...and I can only put
    </applet> one file for "value
    Thanks a lot for ur help!

    you may try the function getScaledInstance(int,int,int) in Class Image.
    the first and second parameters are the width and height you want,the third parameter is hints-flags to indicate the type of algorithm to use for image resampling.

  • How can I display images that are not included in any collection?

    How can I display images that are not included in any collection (some filter or smart collection)? A smart collection with parameters "Collection - contains - empty field" does not work. Lightroom 5.

    Thank you! Good idea! I ordered letters of the alphabet (space separated), and it works.

  • How can I display images in drop down.

    Hi All,
    How can I display images in drop down.
    <select><option>image here</option></select>
    please reply soon.
    anser please
    Thanks

    I have not found html forum..That's just incredible.
    where can i find it ?Sorry, I'm still recovering from that remark.
    please reply soonEvery time you end a post with this, or "urgent" or other such keywords, the forum automatically introduces a 5 minute delay so that will actually make the whole process slower (not faster).

  • How can i display image in RTF template when Oracle Apps running in Windows

    Can any body help how can i display image in RTF template when oracle apps running in Windows Server.
    Thanks
    Ravi

    Hi Ravi,
    You can add images into your rtf template using MS Word Insert Picture feature.
    Did you try this method?
    Thanks
    Ravi
    [email protected]

  • How can i display a image file which is placed in the applications server

    Hi all,
    Can any one help me how can I display a image file which is present in the application server.
    With regards,
    M.Ramana Murthy

    hi,
    *& Form TOP_OF_PAGE
    * text
    FORM F_TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = IT_LISTHEADER
    i_logo = Logo name
    * I_END_OF_LIST_GRID =
    ENDFORM. "TOP_OF_PAGE
    rgds
    Anver

  • How can I attach a jpg file in a mail message as the file icon, not as an opened image in the text?

    How can I attach a jpg file in a mail message as the file icon, not as an opened image in the text?

    what's wrong with this picture

  • How do you display a new image in  webdynpro view?

    How do you display a new image in  webdynpro view?
    Where is the image stored and how do we specify the image path?

    hi ,
    The UI element Image enables you to integrate graphics into the Web application in a format that is processed by the Web Server u2013 for example, GIF, JPG, and PNG format. Height and width of the graphic can be specified using the properties height and width. The graphic is displayed without borders.
    saveur image   as mime
    with Mime Objects u cn upload doc , jpeg, or giff files from our local system into the webdypnpro system .
    Right click on ur component->mime object->import
    In the transaction sicf/bc/webdynpro , u cn check your component name there you can view the mime objects created by you .
    also refer the SAP online help :
    http://help.sap.com/saphelp_crm50/helpdata/en/46/bb182fab4811d4968100a0c94260a5/content.htm
    to knw more abt mime repositories.
    http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    regards,
    amit

  • How do I display a GIF image stored in byte[ ]

    I have a bit of sticky problem and am now stuck. I will post a little code in the hopes someone more clever than I can give me a hand
    I am using a servlet to grab some data from a user, a web service (still within the servlet) is then called that generates a GIF of the user location as
    specified by the address data grabbed from the user input (GET via the url parameters). The byte data is stored in a bean as a byte [ ] and added to the request as an attribute
    via request.setAttribute().
    I then forward to a jsp page that looks like this:
         <html>
         <head>
         <title>Learn Fast or Perish</title>
         </head>
         <body>
         <center>
         <hr>
         </center>
         <h1>Hello World.</h1>
         <jsp:include page="/display" flush="true"/>
         </body>
         </html>.../display maps to another servlet. The doGet portion of the servlet looks like this:
                //response and request are the HTTPServletResponse/Request doGet parameters
                //ImageByteInformation is my bean holding image info in byte [] format
                ImageByteInformation imageByteInfo = (ImageByteInformation) request.getAttribute("imageByteInformation");
                ImageIcon imageIcon = new ImageIcon(imageByteInfo.getByteData());
                Image image = imageIcon.getImage();
                //create a BufferedImage from the image
                BufferedImage bufferedImage = new BufferedImageCreator().createBufferedImage(image);
                System.out.println("BufferedImage length: " + bufferedImage.getHeight() + "BufferedImage width: " + bufferedImage.getWidth());//400 by 600
                System.out.println("BufferedImage string: " + bufferedImage.toString());
                //prints out: BufferedImage@93afae: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width=600 yada yada
                response.setContentType("/image/gif");
                OutputStream stream = response.getOutputStream();
                ImageIO.write(bufferedImage, "gif", stream);
                stream.close();... i found the code above on line and this is supposed to display a GIF to a web page.
    For a while the code was actually prompting if I wanted to download a file of type "/image/gif"?!?
    I did download and save it as temp.gif and the image was there when I opened it on my desktop.
    Something is in the byte array but I cannot get it to display on the page. So what am I doing wrong.
    So my question is this...
    How can I display the gif info stored as a byte [] (byte array) in a bean with a jsp page. I thought including a servlet that
    writes the bytes to the reponse would but no such luck. Is what I am trying possible? This newbie would greatly appreciate
    any advice :)

    First of all the following line is a little off:
    response.setContentType("/image/gif");should be
    response.setContentType("image/gif");What you should do is rather than do an include, try something like the following:
    <img src="/display" />If you're telling me that /display is mapped to the servlet that has the doGet you reference, this would be the proper way to do it.
    HTH.

  • How can I display the name of my refnum on the front panel?

    I am writing data to a file. To do this, I am using "Open/Create/Replace File" to prompt the user for a filename, which is then output to my VI as a refnum. I then write strings to this file with "Write to Text File".
    How can I display this filename (with the path) on the front panel after the user has input it?
    Michael
    Solved!
    Go to Solution.
    Attachments:
    refnum.JPG ‏45 KB

    Use the Refnum to Path function, in File I/O -> Advanced File Functions palette. You can wire this to a path indicator.

  • How can you get a mirror image of a photo on iPhoto?

    How can you get a mirror image of a photo on iPhoto?

    By using an external editor. Preview is already on your Mac. It's called 'Flip Horizontal'
    In order of price here are some other suggestions:
    Seashore (free)
    The Gimp (free)
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    Pixelmator ($50 approx)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate or the App Store.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.

  • I have an old Kodak Photo CD and Photoshop Elements 11 on Windows 7. How can I open the .pcd images?

    I have an old Kodak Photo CD (1999) and Photoshop Elements 11 on Windows 7. How can I open the .pcd images?
    Please help me open these photos. They are very important to me and I need to access them.
    If I can't do it with any of the software installed on my computer, would someone be willing to open them, save them as jpgs and send them to me?
    Thank you so much, Nancy

    You can get the plugin here by downloading the Extra Content for Photoshop CS3  File 2
    Just be sure to follow Note:Very Important Instructions or the link won't work.
    http://prodesigntools.com/download-adobe-cs4-and-cs3-free-trials-here.html
    After downloading the PHSPCS3_Cont_WWE.exe, double click on it to extract the contents, probably to your desktop.
    Then in the Goodies folder, Optional Plugins folder, you'll see the Kodak PhotoCD folder
    Open that and copy the Photo CD.8BI to C:\Program Files (x86)\Adobe\Photoshop Elements 11\Plug-Ins
    Copy the profiles to C:\Program Files (x86)\Common Files\Adobe\Color\Profiles

Maybe you are looking for