Display List of images using ScrollingImagePanel

Hi, following method is called by clicking Next image Button
problem is that he is displaying first image with scrollbar, but second image display without scroll bar and same as third and so on.  
 public void displayImage2(PlanarImage ri)
    {
       
        panel = new ScrollingImagePanel(ri,500, 300);
        getContentPane().add(panel);
        panel.setBounds(50, 300, 500, 300);
    }
LVL 6
MuhammadAdilAsked:
Who is Participating?
 
GyftusConnect With a Mentor Commented:
Hello,

I once had the same problem, it is with revalidating the jComponent after the image has changed.

Question are you overriding paintComponent to add the Image? Are you using a JLabel to set the Image?

These two have very different implications, could you please tell me exactly what ImageScrollingPanel is a subclass of and how the image is being added.

The problem definately lies with the revalidation, revalidate(), and the overriding of the size methods of a JComonent. The ViewPort needs to define its size,
it gets 0,0 before being displayed and that is why the scroll bars dont apear. After it is displayed it has a width and height.

0
 
objectsCommented:
how are you changing the image being displayed?
try (re)validating/repainting the panel after changing the image.
0
 
arun_kuttzCommented:
try inserting a

getContentPane().repaint();

within the loop

-KuTtZ
0
 
Giant2Commented:
I see the same bounds:
500, 300

Try to use different, the scroll bars will appears.

Bye, Giant.
0
 
GyftusCommented:
Thank you for the points, I hope you are solved the problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.