0

i'm doing a gallery with some images (jpanels) into a other jpanel on a jScrollPane but on the scroll is too slow. i have a problem with the repaint of the jpane photos?

@Override protected void paintComponent(Graphics g){
    super.paintComponent(g);

          if(!full){
            height=this.getWidth()*img.getHeight(this)/img.getWidth(this);
            g.drawImage(img, 0, 0,this.getWidth(),height,null);
           }
           else{
            width=this.getHeight()*img.getWidth(this)/img.getHeight(this);
            g.drawImage(img,this.getWidth()/2-width/2, 0,width,this.getHeight(),null);
           }

            g.dispose();
           img.flush();

    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Chtv
  • 1
  • 1
  • 2
    1. Don't dispose of a graphics context you did not create; 2. Use `this` as the `ImageObserver` parameter to `drawImage`; 3. Why do you need img.flush? Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Feb 29 '16 at 21:09
  • 1
    And continuing from @MadProgrammer point 3.. 4) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). – Andrew Thompson Feb 29 '16 at 21:57

0 Answers0