Displaying images in jlabel, jpanel

Hi all,
below is my snippet:
public void actionPerformed(ActionEvent e)
        lblImage.setIcon(new ImageIcon("c:/test"+cnt+".jpg";));
        cnt++;
        if(cnt==6)
            cnt=1;               
        repaint();
    }this actionPerformed() is executed for every 2 seconds. i am displaying continuously 5 pictures in a loop (c:/test1.jpg, c:/test2.jpg...). 5 images are displaying properly. But, they are not of newly updated jpg files. Files used for the 1st loop are used continuously irrespective of newly created files in c: (I am updating these 5 files in c: with another program, updation is proper.). how to show the files properly so that to get motion movie simulation.
please do help.
thanking you.
_________________________

Don't cross post or you won't get help in future. already answered on
[http://forums.sun.com/thread.jspa?threadID=5340639]
db

Similar Messages

  • How to display  image efficiently in JPanel.............

    i have following piece of code used to load and display image on jpanel when application starts.
    the problem is that
    image is not loaded efficiently,
    also it covers other panels added in frame.
    and scrollbar of panel does not work to show parts of image.
    i want to efficiently load the image and to fit in in my panel and also to scroll bar to work proper with image.
    looking for any nice suggestion
    public class MainFrame extends JFrame
    Image image = Toolkit.getDefaultToolkit().createImage("c:\\form-3.jpg");
    javax.swing.JScrollBar jScrollBar1 = new JScrollBar();
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    public MainFrame()
    try
    {            jbInit();        } catch (Exception ex)
    {            ex.printStackTrace();        }
    public static void main(String[] args)
    MainFrame mainFrame = new MainFrame();
    jBInit Method defined here
    public void paint(Graphics g)
    g.drawImage(image,0,0,jPanel1);
    Message was edited by:
    @tif

    You have overided the paint method on JFrame then you are drowing on entire Frame.
    Instead you have to override the paintComponent method of a JPanel class or use a JLabel with the image

  • Displaying Image using JLabel in swings

    I am not understanding how to display a image in swing using JLabel Component.
    I am writing in the following manner:
    // importing necessary packages
    in init() method
    public void init()
    Container cp= getContentPane()
    JLabel jl=new JLabel("Image",new ImageIcon("<image>.gif"),JLabel.CENTER);
    cp.add(jl);
    applet is running and only label msg is displaying but not the image.
    Please help me so that i can solve this problem.where the image is to be placed??and how it has to be included?
    Please provide me the solution.

    cp.add(new JLabel("Image",new ImageIcon(new java.net.URL (getCodeBase(),"Test.gif")),JLabel.CENTER));

  • Problem in displaying images using JLabel in Netbeans

    hi all,
    i am trying to display an image on JLabel in Netbeans.The image is visible in the design view but not displayed in the runtime.Can anyone help me out with suggestions???

    Duplicate - answer here http://forum.java.sun.com/thread.jspa?threadID=5153605&messageID=9578626#9578626

  • Displaying image in jlabel

    when displaying an image in a jlable. the jlabel takes on the size of the image. i have tried to set the maximum bounds to the size of the original size of the jlable and even the panel the jlable sits on, but each time that i go to display the picture, it is displayed huge and not the size of the jlabel it is placed in.
    here is my creation code, my gui was created in netbeans.
    pnImage.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            pnImage.setFocusable(false);
            pnImage.setMaximumSize(new java.awt.Dimension(395, 365));
            lblImage.setFocusable(false);
            lblImage.setMaximumSize(new java.awt.Dimension(395, 365));
            javax.swing.GroupLayout pnImageLayout = new javax.swing.GroupLayout(pnImage);
            pnImage.setLayout(pnImageLayout);
            pnImageLayout.setHorizontalGroup(
                pnImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE)
            pnImageLayout.setVerticalGroup(
                pnImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
            );and here is how i display it.
            Dimension d = pnImage.getSize();
            System.out.println("d = " + d.toString());
            pnImage.setMaximumSize(d);
            lblImage.setMaximumSize(d);
            ImageIcon icon = new ImageIcon(contact.getImage());
            lblImage.setIcon(icon);

    I've never done this (convert a byte array to an image), so I thought I'd have a go...import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    public class ImageTest {
        public static void main(String[] args) throws Exception {
                // Grab some image...
            File inFile = new File("resources/imageH.jpg");
            int len = (int)inFile.length();
            System.out.printf("file length = %d%n", len);
            FileInputStream in = new FileInputStream(inFile);
                // ... and create a byte array for testing
            byte[] byteArray = new byte[len];
            int num = in.read(byteArray);
            in.close();
            System.out.printf("bytes read = %d%n", num);
                // (1) Create an image from the byte array - I don't
                // know Imagio figures out what sort of image it is!
            BufferedImage im = ImageIO.read(new ByteArrayInputStream(byteArray));
            int w = im.getWidth();
            int h = im.getHeight();
            System.out.printf("width = %d, height = %d", w, h);
                // (2) Scale to fit 100x100
            if(w > h) {
                w = (100 * w) / h;
                h = 100;
            } else {
                h = (100 * h) / h;
                w = 100;
            System.out.printf(" --> %d,%d%n", w, h);
                // (3) And create the icon
            ImageIcon icon = new ImageIcon(im.getScaledInstance(w, h, Image.SCALE_SMOOTH));
            System.out.printf("The icon is: %s%n", icon);
    }The output isfile length = 54918
    bytes read = 54918
    width = 500, height = 300 --> 166,100
    The icon is: javax.swing.ImageIcon@5afd29Assuming your byte array is some (to ImageIO) recognisable image format, something
    similar should work for you.

  • Question about displaying image with JLabel

    Hi
    I need to display an image. The image is determined by the user at run time, so the dimension of the image is unknown. Is it possible for JLabel to stretch the image so the whole image(instead of only part of it) will always fits into a certain dimension?
    thanks.

    For this you need to create a custom class that extends ImageIcon
    and define the methods there.
    see Java Tutorial for it.
    For eg., to scale an image , you can use
    JLabel label = new JLabel();
    Image img = new ImageIcon("Pics/Ash.jpg").getImage();
    int width = img.getWidth(null);
    int height = img.getHeight(null);
    //This would scale the Image by 200%
    Image bimg = image.getScaledInstance(width*2, height*2, Image.SCALE_SMOOTH);
    label.setIcon(new ImageIcon(bimg));
    //There is also another way
    //Use drawImage and use BufferedImage
    BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = buff.getGraphics();
    //Scale the Image to 200%
    g.drawImage(img, 0, 0, width*2, height*2,  null);
    lable.setIcon(new  ImageIcon(buff));Hope you get the idea!!

  • Displaying images on a JPanel from another thread

    Hello all,
    I'm trying to write my first multithreaded program. I have a program with 2 threads. The first (ie main) thread sets up a gui and performs some calculations, and the second thread changes the background of the gui at intervals. I been having a couple of problems with loading images in the second thread.
    In my main thread, I initialise and make runnable the second thread, which is the thread that changes the gui background:
    ThreadChangeBackground myThread = new ThreadChangeBackground(graphicPanel);
    new Thread(myThread).start(); I have tested the threads and they are working fine.
    The problem is when I try to load images and show them. I've never worked with images before, so I don't know what the best way of loading them onto a GUI is.
    This is the code for the second thread:
    package Graphics;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Container.*;
    import java.awt.Toolkit.*;
    public class ThreadChangeBackground implements Runnable
        JPanel changeable; //changeable = graphicPanel
        Image bgImage1;
        Image bgImage2;
        Image bgImage3;
        Image bgImage4;
        Image bgImage5;
        Image bgImage6;
        Image bgImage7;
        Image bgImage8;
        Image bgImage9;
        Image bgImage10;
        public ThreadChangeBackground(JPanel changeable)
            this.changeable = changeable;
        public void run()
            try
                bgImage1 = Toolkit.getDefaultToolkit().getImage("1");
                bgImage2 = Toolkit.getDefaultToolkit().getImage("2");
                bgImage3 = Toolkit.getDefaultToolkit().getImage("3");
                bgImage4 = Toolkit.getDefaultToolkit().getImage("4");
                bgImage5 = Toolkit.getDefaultToolkit().getImage("5");
                bgImage6 = Toolkit.getDefaultToolkit().getImage("6");
                bgImage7 = Toolkit.getDefaultToolkit().getImage("7");
                bgImage8 = Toolkit.getDefaultToolkit().getImage("8");
                bgImage9 = Toolkit.getDefaultToolkit().getImage("9");
                bgImage10 = Toolkit.getDefaultToolkit().getImage("10");
                //run this thread process 200 times
                for (int i = 1; i <= 200; i++)
                    //load a new image every 3 seconds
                    for (int imageCount = 1; imageCount <= 10; imageCount++)
                        loadImage(imageCount);
                        Thread.sleep(3000);
            catch (Exception e) {}
    //the problem is here 
        private void loadImage(int imageNo)
            Graphics g = changeable.getGraphics();
            g.drawImage("bgImage" + imageNo, 400, 500, null);
    }The API suggests using getGraphics() to get the graphics context of a component. This allows you to invoke operations on the returned graphics object to draw on the component. When I try to call drawImage() i get the following error message:
    Graphics/ThreadChangeBackground.java [57:1] cannot resolve symbol
    symbol  : method drawImage (java.lang.String,int,int,<nulltype>)
    location: class java.awt.Graphics
            changeable.getGraphics().drawImage("bgImage"+ imageNo, 400, 500, null);
                                  ^
    1 error
    Errors compiling ThreadChangeBackground.If I change the code and try to do this:         g.drawImage("bgImage" + imageNo, 400, 500, null); everything complies but the background of my gui does not change. Adding changeable.repaint() to the loadImage() method does not change the gui background.
    I've got this far by reading the API (it's so big!), java textbooks and the java tutorial, but I really don't know what to do next.
    Any help would really be appreciated!

    These are all the drawImage methods in Graphics class:
    abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
    Draws as much of the specified image as is currently available.
    abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
    Draws as much of the specified image as is currently available.
    abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
    Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
    abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
    Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
    abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
    Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
    abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
    Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
    Notice that NONE of them takes String as the first argument.
    Your error:
    Cannot resolve symbol method drawImage (java.lang.String,int,int,<nulltype>)
    suggests that java is looking for drawImage method that takes String as its first argument - IT'S NOT IN THE GRAPHICS CLASS - that's the problem
    M
    suggests

  • Display image in JPanel without saving any file to disk

    Hi,
    I am fetching images from database. I am saving this image, display in JPanel and delete it. But this is not actually I want.
    I wish to fetch this image as stream , store in memory and display in JPanel without saving any fiel in disk.
    I wonder if it is Possible or any used implementation that I can use in my project. Any idea or experienced knowledge is enough.
    Thanks

    In what format is the image coming to you from the database? If it's an InputStream subclass, just use javax.imageio.ImageIO:
    InputStream in = getImageInputStream();
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have beenIf you receive the image as an array of bytes, use the same method as above, but with a ByteArrayInputStream:
    byte[] imageData = getImageData();
    ByteArrayInputStream in = new ByteArrayInputStream(imageData);
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have been

  • Two problems with displaying images in JPanel

    Hi,
    I need to display some small rectangular images inside a JPanel. These images also need to be componenents as they will have listeners associated with them. I have never had any experience with images, so I might totally be down the wrong path. I was thinking of just creating a class which extends JComponent, and using the graphics drawImage method. However, I don't want each image component to have to know exactly where to draw the image associated with itself. Rather, I want the JPanel which holds all of the images to know how to lay them out.
    Is there an easier way to use images?
    Which brings me to my second problem. I want these images to overlap each other, so that only a small portion of each is showing (this way I can fit more on the screen), then when the user clicks on one, I can show more of it.
    Unfortunately, I don't know of any layout managers which will allow me to overlap components. I could use the drawImage method mentioned above, but like I said, I would like to try to not have each image object try and figure out its location.
    any help is greatly appreciated. Thanks!

    Hi
    there is a better way ; it is called a JLabel ;-)
    JLabel myJLabel = new JLabel(new ImageIcon("img/myLogo.gif"));for your second problem, don't use any layout manager like in this code :
    myJPanel.setLayout(null);
    myJPanel.add(myJLabel);
    myJLabel.setBounds(new Rectangle(x, y, width, height);hope it helps
    Nico

  • Problem displaying image in jpanel

    Hi,I have posted this on the applet board, but I think its also a general programming problem, so apologies if it isn't relevant to this board, just say so and I'll remove it!
    I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
    I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
    the code I currently have is:
    // get image url
    String mapURL = getParameter("mapURL");
    //set variable for image
    Image map_png;
    // set media tracker
    MediaTracker mt;
    //initialise media tracker     
    mt = new MediaTracker(this);
    map_png = getImage(getDocumentBase(),mapURL);
    // tell the MediaTracker to kep an eye on this image, and give it ID 1;
    mt.addImage(map_png,1);
    // now tell the mediaTracker to stop the applet execution
    // until the images are fully loaded.
    try
    mt.waitForAll();
    catch (InterruptedException e) {}
    // draw image onto mapPane
    mapPane.getGraphics().drawImage(map_png, 200, 200, null);
    Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
    Cheers
    Steve

    hi,
    No, don't get any exceptions, the Java Console has a message:
    <terminated>JavaImageEditor[Java Applet]C:\Program Files\Java\jre1.6.0\bin\javaw.exe
    Cheers
    Steve

  • Displaying images in JPanel

    Hi,
    I'm trying to work out the best method to display a set of thumbnail images in a JPanel (similar to a Thumbnail view in windows XP) - at the moment I'm using a Tree, but am wondering whether this is the best way to go about it? I'm using a tree in combination with a TreeModel but am having some problems as the cells don't expand to fit the picture size. Any ideas appreciated!!
    thanks
    Jonathan

    Why dont you use a JTable?

  • Problems displaying image in JPanel

    Hi, I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
    I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
    the code I currently have is:
    // get image url
            String mapURL = getParameter("mapURL");
            //set variable for image
            Image map_png;
            // set media tracker
            MediaTracker mt;
            //initialise media tracker             
            mt = new MediaTracker(this);
            map_png = getImage(getDocumentBase(),mapURL);
            // tell the MediaTracker to kep an eye on this image, and give it ID 1;
            mt.addImage(map_png,1);
            // now tell the mediaTracker to stop the applet execution
            //  until the images are fully loaded.
            try
                 mt.waitForAll();
            catch (InterruptedException  e) {}
            // draw image onto mapPane
            mapPane.getGraphics().drawImage(map_png, 200, 200, null);Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
    Cheers
    Steve

    Hello,
    after an update of the graphics card driver to the newest just released version the problem has vanished.
    Regards

  • Simple and efficient way to display image on jpanel

    AOA
    What may be the simple and efficient way
    to display a strored jpg image on a jpanel in an application.
    i will appreciate more than one ways.
    thanks

    JPanel panel = new JPanel() {
         public void paintComponent(Graphics g) {
                   g.drawImage(......);
    };

  • Displaying image in JPanel and scroll it through JScrollpanel

    Can any one will help me,
    I need to draw a image in a JPanel and, this JPanel is attached with a Jscrollpanel.
    I need to scroll the this JPanel to view the image.

    Here is my code for that
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PicPanel extends javax.swing.JPanel implements WindowListener{
    /** Creates new form PicPanel */
    public PicPanel() {
    initComponents();
    // this.setOpaque(true);
    JFrame myFrame = new JFrame("Panel Tiler");
    myFrame.addWindowListener( this );
    myFrame.setSize(new Dimension(1000,300));
    setPreferredSize(new Dimension(1000,300));
    Container cp = myFrame.getContentPane();
    cp.add( this, BorderLayout.CENTER );
    tk = Toolkit.getDefaultToolkit();
    im =tk.getImage("smple.jpg");
         jPanel1.im=im;
    // jPanel1.setSize(new Dimension(1000,300));
    myFrame.pack();
    myFrame.show();
    jPanel1.repaint();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;
         jPanel1=new JPanelC();
    jScrollPane1 = new javax.swing.JScrollPane(jPanel1);
    setLayout(new java.awt.GridBagLayout());
    jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane1.setOpaque(false);
         gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 378;
    gridBagConstraints.ipady = 298;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    add(jScrollPane1, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.ipadx = 372;
    gridBagConstraints.ipady = 280;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    add(jPanel1, gridBagConstraints);
    public static void main(String[] args)
    new PicPanel();
    public void windowOpened(WindowEvent e) {}
    public void windowClosing(WindowEvent e)
    // myFrame.dispose();
    System.exit(0);
    public void windowClosed(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
    private JPanelC jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private Icon iiBackground;
    private Toolkit tk;
    private Image im;
    class JPanelC extends javax.swing.JPanel{
    public Image im;
    public void paintComponent(Graphics g){
              //super.paintComponent(g);
    if(im!=null)
                   imageobserver io = new imageobserver();
         System.out.println(im.getHeight(io));
         if(im.getHeight(io)!=-1)
    setSize(im.getWidth(io), im.getHeight(io));
    g.drawImage(im,0,0,null);
         // setOpaque(false);
    super.paintComponent(g);
    class imageobserver implements java.awt.image.ImageObserver{
    public boolean imageUpdate(Image img, int infoflags, int x, int y,int width, int height) {
              if ((infoflags & java.awt.image.ImageObserver.ALLBITS) != 0) {
    repaint();
    return false;
    //repaint();
    return true;
    Here i need to scroll the image in the panel but it is not working out.

  • Open and display image in MVC layout

    Hello!
    I cant figure out how I shall do this in an MVC layout:
    The program request user to open an image file that are then displayed in a JLabel
    My setup at the moment resolve in a nullpointerexeption because it dont get any actual image file, but I dont understand what I have missed.
    I can not post the whole code fo you to run because it is to big, so I post the part that are the most important. please have a look.
    PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }From my model:
    //Local attributes
         boolean check = false; //Used to see if a statement is true or not
         PicturePanel pp;
         JFileChooser fc;
         int returnVal;
    //newFile in File menu
         public void newFile() {
              //Open a file dialog in users home catalog
              fc = new JFileChooser();
              //In response to a button click:
              returnVal = fc.showOpenDialog(pp);
              System.out.println("You pressed new in file menu");
         }From my controler:
    //User press "New" in File menu
              else if (user_action.equals("New")) {
                   //Call method in model class
                   model.newFile();
                   //Update changes
                   if (model.returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("Hello1");
                        File f = model.fc.getSelectedFile();
                        if (model.pp != null)     
                             model.pp = new PicturePanel(f.getAbsolutePath());
                        System.out.println("Hello2");
                        //Display image (Here is line 83)
                        view.setImage_DisplayArea(model.pp);
                        System.out.println("Hello3");
              }From my view:
    //Sets the image to be displayed on the image_display area (Here is line 302)
         public void setImage_DisplayArea(PicturePanel pp) {
              image_display.add(pp);
         }The complet error:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at java.awt.Container.addImpl(Container.java:1015)You pressed new in file menu
    Hello1
    Hello2
         at java.awt.Container.add(Container.java:351)
         at View_Inlupp2.setImage_DisplayArea(View_Inlupp2.java:302)
         at Control_Inlupp2.actionPerformed(Control_Inlupp2.java:83)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
         at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1050)
         at apple.laf.CUIAquaMenuItem.doClick(CUIAquaMenuItem.java:119)
         at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1091)
         at java.awt.Component.processMouseEvent(Component.java:5602)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
         at java.awt.Component.processEvent(Component.java:5367)
         at java.awt.Container.processEvent(Container.java:2010)
         at java.awt.Component.dispatchEventImpl(Component.java:4068)
         at java.awt.Container.dispatchEventImpl(Container.java:2068)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
         at java.awt.Container.dispatchEventImpl(Container.java:2054)
         at java.awt.Window.dispatchEventImpl(Window.java:1801)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Edited by: onslow77 on Dec 16, 2009 5:00 PM
    Edited by: onslow77 on Dec 16, 2009 5:04 PM

    Hello again!
    Anyone that can help me figure out how to implement this in an MVC layout, I feel stuck.
    I post a little program that open and display an image file so that you better can understand what I whant to do.
    ShowImage
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.filechooser.*;
    public class ShowImage extends JFrame{
         //Variables
         JFileChooser fc = new JFileChooser();
         PicturePanel pp = null;
         ShowImage () {
              super("Show"); //Title
              //Create the GUI
              JPanel top = new JPanel();
              add(top, BorderLayout.NORTH);
              JButton openBtn = new JButton("Open");
              top.add(openBtn);
              openBtn.addActionListener(new Listner());
              //Settings for the GUI
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              pack();
              setVisible(true);
         class Listner implements ActionListener {
              public void actionPerformed(ActionEvent ave) {
                   int answer = fc.showOpenDialog(ShowImage.this);
                   if (answer == JFileChooser.APPROVE_OPTION){
                        File f = fc.getSelectedFile();
                        //Check
                        System.out.println(f);
                        System.out.println(pp);
                        if (pp != null)
                             remove(pp); //Clean so that we can open another image
                        //Check
                        System.out.println(pp);
                        //Set the PicturePanel
                        pp = new PicturePanel(f.getAbsolutePath());
                        //Check
                        System.out.println(pp);
                        //Add PicturePanel to frame
                        add(pp, BorderLayout.CENTER);
                        validate();
                        pack();
                        repaint();
         //Main
         public static void main(String[] args) {
              new ShowImage();
    }PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }//The endEdited by: onslow77 on Dec 16, 2009 7:30 PM

Maybe you are looking for