Swing:孩子可以超越父母的界限吗?
在 Swing 中,子级 JComponent
是否可以在其父级 JComponent
的边界之外呈现,或者子级是否始终被剪切到其父级的边界?
In Swing, can a child JComponent
be rendered outside of the bounds of its parent JComponent
, or are children always clipped to the bounds of their parent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要子组件是轻量级组件,它就会被限制在父组件的边界内。但是,如果太大,则会被剪切,不会进行缩放。
如果子组件是重量级组件而父组件是轻量级组件,则子组件将在父组件边界之外渲染。
这里有一篇关于此的非常好的文章:http://java.sun。 com/developer/technicalArticles/GUI/mixing_components/index.html(不记得是谁推荐给我的,但谢谢!)
还有一个更新,我不知道(在链接中):
As long as the child is a light-weight component, it will be limited to the boundaries of the parent component. However, if it is too big, It will be cut, no scaling will be done.
If the child is a heavy weight component and the father is light-weight component, the child will be rendered outside of the parent bounds.
There's a really nice article about this here: http://java.sun.com/developer/technicalArticles/GUI/mixing_components/index.html (can't remember who referred me to it but thanks!)
One more update, which I wasn't aware of (in the link):
实际上,您可以重置paint()方法中使用的Graphics实例的剪辑边界。只需保存旧剪辑,设置新剪辑,在父边界之外进行绘画,然后将原始剪辑设置回去。
Actually You can reset clip bounds of the Graphics instance used in paint() method. JUst save old clip, set new, do your painting outside the parent bounds and set original clip back.