开发者

Swing : Can children exceed the bounds of their parent?

In Swing, can a child JCompon开发者_Go百科ent be rendered outside of the bounds of its parent JComponent, or are children always clipped to the bounds of their parent?


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):

As of the JDK 6 Update 12 and JDK 7 build 19 releases, it is now possible to seamlessly mix heavyweight and lightweight components within the same container.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜