玻璃板与分层玻璃的用例
我一直对玻璃板和分层玻璃之间的区别有点模糊。玻璃板本质上只是“根玻璃的最顶层”,还是它的行为有所不同?什么时候会使用分层窗格而不是玻璃窗格?
I've always been a little fuzzy on the difference between the glass pane and a layered pane. Is the glass pane essentially just "the very top layer of the root pane," or does it behave differently? When would you use a layered pane instead of the glass pane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们是两个不同的东西:
分层窗格是在
JFrame
中添加或显示的所有内容的目标。例如,每个普通组件如JLabels
、JTextFields
、JTable
等。此外,它还隐式处理添加到的元素的 z 顺序它可以处理弹出菜单或拖放效果:这是因为弹出菜单被添加到分层窗格中,其 az 高于普通组件,最终效果保持在其他内容之上。请参阅此处以更好地了解该行为。< /p>玻璃窗格是一个可选层,默认情况下是隐藏的,并且在任何情况下都保留在图层窗格的顶部。因此,基本上您在玻璃板上绘制的所有内容都将始终可见:您可以将其视为应用在普通
JFrame
顶部的透明纸,您可以根据需要选择使用它.分层窗格和玻璃窗格都放置在根窗格上,根窗格是构建每个框架的基础。
They are two different things:
the layered pane is the destination of all the contents that are added or shown inside a
JFrame
. For example, every normal component likeJLabels
,JTextFields
,JTable
etc.. in addition it implictly handles z-ordering of elements that are added to it so it can handles popup menus, or drag and drop effects: this because a popup menu is added to the layered pane with a z higher than the normal components, with the final effect to stay on top of other things. See here to understand the behaviour better.the glass pane is an optional layer that is hidden by default and stays in any case on top of the layer pane. So basically everything you draw onto the glass pane will be always visible: you can think of it as a trasparent sheet that is applied on the top of a normal
JFrame
that you can choose to use you need special effects.Both the layered pane and the glass pane are placed on the root pane that is the basis from which every frame is built up.