Problems with scrollbar in java Layered Panes

I am trying to create this little java application. I find it very difficult to design a user interface in Java, tasks that seem very simple become complex and all these strange distortions occur. In my application, I created a JLayeredPane that contains two layers. One on top of the top, they both contain scrollbars. Here's an explanation of the two layers:

Layer 1: A very large image inside something that looks like a scroll. The image scrolls.

Level 2: A graphics2d object, this object draws an image. Once the image reaches a certain length, the layer will get scrolling, which will advance with the drawing over time.

I would like to connect both levels. I want the second layer to update the scrollbar at level 1. Bearing in mind that once it reaches a certain length, both scrollbars will advance together. When I try to do this, the two scrollbars do move forward , but (!) It's weird flickering. I don't understand what is the reason for the flickering. Is there any other way to implement this in a simple way? I should have a second layer on top of the first one (picture above)

since I cannot open a dedicated post to thank the wonderful people of this forum, I will do it here. Thank you, you helped a lot. I hope this problem is also solvable.

+2


source to share


2 answers


It looks like you are repainting the entire component every time in an expensive way - you can try to paint the BufferedImage to save the image rather than re-generating it every time. Or you can try to combine with how repeaters are handled. I would suggest this article and this page on the Sun website - discussing practical painting techniques.



+1


source


Without seeing your code, it's pretty hard to guess where the problem is. You are probably getting more paint () than you really need.



Also you can try JXLayer ( http://weblogs.java.net/blog/alexfromsun/archive/2008/06/the_new_jxlayer.html ) to show your graphics2d level.

0


source







All Articles