I use NetBeans and I wanted to show an image on a jPanel (basically to make it scroll). I wrote this code
    Graphics g=jPanelScrolling.getGraphics();
    File fileBackground = new File("background.jpg");
    Image background;
    try{
        background=ImageIO.read(fileBackground);
        final int WIDTH=background.getWidth(rootPane);            
        final int HEIGHT=background.getHeight(rootPane);
        g.drawImage(background, WIDTH, HEIGHT, rootPane);
    }
    catch(IOException e){
        background=null;
        jPanelScrolling.setBackground(Color.red);  //to test if the image has been succesfully uploaded
    }
but when I execute it, it shows me only the void jPanel
How can I make it work?
 
     
    
