Swing JLayeredPane.getLayer() - 文档错误或实际副作用?
我试图弄清楚 JLayeredPane 在 Swing 中。 如果有人使用过这个类,反馈将不胜感激。
getLayer(JComponent c) 的文档指出:
获取图层属性 JComponent,它不会引起任何方面 类似 setLayer() 的效果。 (绘画, 添加/删除等)通常你应该 使用实例方法 getLayer()。
显然,这里存在一些错误,因为这是实例方法 getLayer() (没有重载版本)
实际上是否应该在此处进行不同的调用,或者是否有人太急于从 putLayer() 进行复制:
设置图层属性 JComponent。 该方法不会导致 任何副作用,如 setLayer() (绘画、添加/删除等)。 通常情况下 你应该使用实例方法 setLayer(),为了得到 期望的副作用(例如 重新绘制)。
I'm trying to figure something out about JLayeredPane in Swing. If anyone has used this class, feedback would be appreciated.
The documentation for getLayer(JComponent c) states:
Gets the layer property for a
JComponent, it does not cause any side
effects like setLayer(). (painting,
add/remove, etc) Normally you should
use the instance method getLayer().
Clearly, there is some mistake here since this is the instance method getLayer() (there aren't overloaded versions)
Is there actually a different call that should be made here, or was somebody just too eager in copying from putLayer():
Sets the layer property on a
JComponent. This method does not cause
any side effects like setLayer()
(painting, add/remove, etc). Normally
you should use the instance method
setLayer(), in order to get the
desired side-effects (like
repainting).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像 Swing 中的许多事情一样,您的问题的答案在 swing 源代码中揭示。 来自 JLayeredPane.java:
看起来您在这里看到一些差异的原因是 JComponent 实例的层存储为 JComponent 实例的属性,但 Component 实例的层存储在 JLayeredPane 的哈希表中。 因此, getLayer(JComponent c) 可以是静态的,而 getLayer(Component c) 则不能。
正如您可能想象的那样,这只是这个类的奇怪之处的开始。 验证和绘制 JLayeredPane 和内容可能很快就会变得复杂。
Like many things in Swing, the answer to your question is revealed in the swing source code. From JLayeredPane.java:
It looks like the reason you are seeing some differences here is that the layer of a JComponent instance is stored as a property of the JComponent instance, but the layer of a Component instance is stored within a hashtable of JLayeredPane. Hence, getLayer(JComponent c) can be static while getLayer(Component c) cannot.
As you might imagine, this is just the start of the strangeness of this class. Validating and painting JLayeredPane and contents can get complicated quickly.