Java分层窗格中的滚动条问题 [英] scroll bar problems in java Layered Panes

查看:211
本文介绍了Java分层窗格中的滚动条问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试构建这个小型Java应用程序.我发现用Java设计UI非常困难,看似非常简单的任务变得复杂,并且所有这些奇怪的行为都会发生.在我的应用程序中,我创建了一个包含两层的JLayeredPane.一个在另一个之上,它们都包含滚动条. 这是对两层的解释:

I've been trying to build this small java app. I find it very difficult to design UI in java, tasks that seem very simple become complicated and all these strange misbehaviors occur. In my app I've created a JLayeredPane which contains two layers. One on top on the other, They both contain scrollbars. Here's an explanation of the two layers:

第1层: 类似于滚动窗格的内部非常大的图像.图片是可滚动的.

Layer 1: A very big image inside something similar to a scrollpane. The image is scrollable.

第2层: 一个graphics2d对象,此对象绘制图像.一旦图像达到一定长度,该图层就会获得一个滚动窗格,该滚动窗格会随着时间的推移随着绘图的发展而前进.

Layer 2: A graphics2d object, this object draws an image. Once the image reaches a certain length, the layer gets a scrollpane that advances with the drawing with time.

我想连接两层.我希望第二层更新第1层上的滚动条.这意味着一旦达到一定长度,两个滚动条就会一起前进.当我尝试这样做时,两个滚动条确实会前进,但但是(!)会发生这种奇怪的闪烁.我不明白闪烁的原因是什么.还有其他方法可以以简单的方式实现吗?我必须将第二层放在第一层的顶部(在图像顶部绘制)

I'd like to connect both layers. I want layer two to update the scrollbar on layer 1. Meaning that once it reaches a certain length, both scrollbars will advance together. When I try doing that, the two scroll bars really do advance, but ( ! ) this strange flickering occurs. I don't understand what is the reason for the flickering. Is there any other way to implement this in a simple manner? I must have the second layer on top of the first one (drawing on top of image)

由于我无法打开特别的帖子来感谢这个论坛的精彩人士,因此我将在此处进行.谢谢,您的帮助很大.我希望这个问题也可以解决.

since I cannot open a special post for thanking the wonderful people of this forum, I'll do it here. Thank you, you are great help. I hope this problem is solvable as well.

推荐答案

听起来您每次都在以某种昂贵的方式重新绘制整个组件-您可以尝试绘制到BufferedImage上以保存图像,而不必重新每次生成它.或者,您可以尝试弄乱如何处理重绘.我建议此文章和此

It sounds like you're repainting the entire component in some costly way each time - you could try to paint to a BufferedImage to save the image rather than re-generate it each time. Or you could try to mess around with how repaints are handled. I'd suggest this article and this page on Sun's website - both discuss performant painting practices.

这篇关于Java分层窗格中的滚动条问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆