Swing:有没有一种简单的方法可以让 1 个组件忽略布局管理器?
我有一个 JPanel,其中有一个组件我想以绝对的方式放置,而其余组件则根据布局管理器放置。
有没有一种简单的方法可以做到这一点?
I have a JPanel with one component that I want to place in an absolute sense, whereas the rest of the components are placed according to a layout manager.
Is there a simple way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是说您想要将一个组件绘制在所有其他组件之上吗?如果是这样,那么您将需要使用 JLayeredPane。
您为什么不发布一个 SSCCE 来演示您想要做什么?
您可以像平常一样将组件添加到框架并使框架可见。然后你可以添加这个随机组件并在该组件上使用 setBounds 。只要您不重新验证()面板或调整框架大小,我们就能够看到您打算如何相对于所有其他组件定位该组件。
Are you saying you want a component painted over top of all the other components? If so then you would need to use a JLayeredPane.
Why don't you post a SSCCE that demonstrates what you want to do?
You can add components to a frame as you would do normally and make the frame visible. Then you can add this random component and use setBounds on the component. As long as you don't revalidate() the panel or resize the frame we will be able to see how you intend to position this component relative to all the other components.
您可能还想查看
OverlayLayout
,参见此处。由于某种原因,它被排除在传统的图库之外,但它可能感兴趣。
You might also want to look at
OverlayLayout
, seen here. For some reason it's excluded from the conventional gallery, but it may be of interest.您只需使用 MigLayout 一个 JPanel 即可完成此操作
You can do this with only needing one JPanel using MigLayout