hell_tej 5 Junior Poster in Training

I am working on a project which requires to display image dynemicaly by selecting the JTable record.

At the First time selection Image displayed. BUT when i click on another row of JTable Image can't Update i use repaint method also to drow again the Panel but it can't works.

the code of Image on JPanel is as follows.

/*Function which add the Jpanel to JFrame. it is JFrame Class Method*/
public void imageLoad(ResultSet tmprs1)
    {
         BufferedImage bimg = null;
         String path = null;
         try
         {
             connect();
             path = tmprs1.getString("photo");
         }
         catch(Exception e)
         {
             System.out.println("Error in Image Connection"+e);
         }
        try
        {
            // Track the image to completion.
            bimg = ImageIO.read(new File(path));
            JPanel cont = (JPanel) getContentPane();
            imgobj = new NewClass(bimg);
            imgobj.setBounds(420,30, 150, 150);
            cont = new NewClass(bimg);
            imgobj.setImage(bimg);
            Image img = imgobj.getImage(bimg);
            imgobj.prepareImage(imgobj.getImage(bimg), this.getHeight(),this.getWidth(), null);
            System.out.println(path);
            //getContentPane().add(imgobj,BorderLayout.CENTER);
            jPanel2.add(imgobj);//Tab Panel
        }
        catch(Exception e)
        {
            System.out.println("the error in frame..."+e);
        }
    }


/* CLASS which Extends the JPanel to display Image*/
class NewClass extends JPanel implements Serializable {
    Image image = null;
    public NewClass() {    
    }
    public NewClass(Image image) {
        this.image = image;
        repaint();
        System.out.println("Class Panel Constructed...");
    }
   public void setImage(Image image){
        this.image = image;
         repaint();
        //update(g);
        System.out.println("Image set...");
    }
        public Image getImage(Image image){
        return image;
        
    }
        @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g); //paint background
        if (image != null) { //there is a picture: draw it
            int height = this.getSize().height;
            int width = this.getSize().width;         
            g.drawImage(image,0,0, width, height, this);
            System.out.println("paint Component method ...");
               //g.drawImage(image, 0, 0, this); //original image size 
         }  //end if
    } //end paint
} //end class

I tryed so much but Image not change Dynemically by user
Please Help............:'(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.