Java Swing 组件上的 Z 顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4229638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Z-order on Java Swing components
提问by Bevin
I've been looking all over for some mention of this, but I cannot find any substantial information on it. Is there a way to change the z-order of Swing components, or at least change the draw order so that they appear to be above others?
我一直在寻找有关此事的一些内容,但我找不到任何关于它的实质性信息。有没有办法更改 Swing 组件的 z 顺序,或者至少更改绘制顺序,使它们看起来高于其他组件?
采纳答案by Amir Afghani
回答by Reverend Gonzo
If you want to overlay components over other components, you should use JLayeredPane, which will let you add components to specific layers. This is precisely what's used for things like tooltips and drag-and-drop operations.
如果您想将组件覆盖在其他组件上,您应该使用JLayeredPane,它可以让您将组件添加到特定层。这正是用于工具提示和拖放操作之类的内容。
Here's a tutorialfor it as well.
这里还有一个教程。
回答by camickr
Look at the setComponentZOrder(...) method of the Container class.
查看 Container 类的 setComponentZOrder(...) 方法。
You can also check out the Overlap Layoutwhich has a brief description on how ZOrder works.
您还可以查看重叠布局,其中简要介绍了 ZOrder 的工作原理。