JPanel 中的自动循环滚动活动内容 - 选取框文本
我需要一些自动循环滚动(选取框文本),它的内容是 JPanel
。它的内容必须对鼠标点击不同元素做出反应。因此,仅使用移动的坐标绘制内容在这里不起作用,因为元素的实际位置没有改变。 它还必须能够更新。最有可能的是,它将是平滑的更新 - 没有任何弹跳。 尝试使用没有可见滚动条和自动滚动的 JScrollPane
,它可以容纳动作侦听器,但我无法使其平滑循环和平滑更新内容。
更新 它应该看起来像这样:
http://h1.flashvortex.com/display.php?id=2_1311593920_25605_144_0_700_30_6_1_92
但可以通过代码修改内容,而不停止动画和弹跳。
I need some auto loop-scrolling (marquee text) it's contents JPanel
. It contents must react on mouse clicking on different elements. So just drawing contents with moved coordinates not working here, because real position of elements not changing.
Also it must be update able. Most likely that it will be smooth update - without any bouncing.
Tried to use JScrollPane
with no visible scrollers and auto-scrolling, it can hold action listeners, but I can't make it smooth looping and smooth updating contents.
UPDATE
it should looks like this:
http://h1.flashvortex.com/display.php?id=2_1311593920_25605_144_0_700_30_6_1_92
but with modifying contents from code, without stopping animation and bouncing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您或许可以使用选取框面板。该代码使用真实的组件,因此您应该能够添加添加到组件的任何侦听器并对其做出反应。
编辑:
哎呀,我不知道我在想什么,我的代码使用 Graphics.translate(...) 方法来绘制组件,因此直接使用 MouseListener 是行不通的。
Edit2:
也许下面的代码会有帮助。只需将该方法添加到 MarqueePanel 类中即可:
现在您可以将 MouseListener 添加到 MarqueePanel 中,然后调用此方法以确定为哪个组件生成 MouseEvent。一旦您知道单击了哪个组件,您将需要手动调用该组件的操作。或者您可以尝试将 MouseEvent 重新分派给组件。您需要重新创建 MouseEvent 以使组件成为事件源,而不是面板成为事件源。您还需要将事件 X/Y 位置隐藏为相对于组件而不是面板。 SwingUtils 类应该对此有所帮助。
You might be able to use the Marquee Panel. The code uses real components so you should be able to add and react to any listener you add to the components.
Edit:
Oops, I don't know what I was thinking, my code uses the Graphics.translate(...) method to paint the components so using a MouseListener directly won't work.
Edit2:
Maybe the following code will help. Just add the method to the MarqueePanel class:
Now you can add a MouseListener to the MarqueePanel and then invoke this method in order to determine which component the MouseEvent was generated for. Once you know which component was clicked you will manually need to invoke an Action for that component. Or you could try redispatching the MouseEvent to the component. You wouuld need to recreate the MouseEvent to make the component the source of the event instead of the panel being the source. You would also need to covert the event X/Y locations to be relative to the component and not the panel. The SwingUtils class should help with this.
MarqueePanel 包括
start()
和 <代码>stop() 方法;它可能是一个有用的起点,但您必须考虑出一个update()
方法。附录:由于示例使用了
JLabel
,它不能就地编辑。如果使用JTextField
,更新相应的模型Document
可能是最简单的方法。MarqueePanel includes
start()
andstop()
methods; it might make a useful starting point, but you'll have to factor out anupdate()
method.Addendum: As the example uses a
JLabel
, it cannot be edited in situ. If using aJTextField
, it may be easiest to update the corresponding model,Document
.