如何使用 MiGLayout 将组件置于包含多个组件的行上居中
我大约一个半月前开始使用 MiGLayout,一切都很简单,而且效果很好。只有一个问题我仍然无法解决。
假设我想要一行最右侧有两个按钮和一个居中标题,当我这样做时,标题实际上并没有居中:(
“this”是一个 JPanel)
this.add(labelTitle, "split, span, center");
this.add(closeButton, "east");
this.add(mainMenuButton, "east");
会发生什么“labelTitle”在放置按钮后的剩余可用空间中居中,但我实际上希望它相对于整个 JPanel 居中,而不仅仅是剩余空间。
我可以使用哪些参数来获得所需的效果?我知道我可以使用绝对定位,但我不想这样做,因为在我的例子中,它首先违背了使用 MiGLayout 的目的。
I started using MiGLayout about a month and half ago and everything is simple and works great. There's only one issue I still have that I haven't been able to fix.
Let's say I want to have a row that has two buttons on the right-most side and a centered title, the title doesn't actually get centered when I do it this way:
("this" is a JPanel)
this.add(labelTitle, "split, span, center");
this.add(closeButton, "east");
this.add(mainMenuButton, "east");
What happens is that "labelTitle" is centered in the remaining space available after the buttons are placed, but I actually want it to be centered relative to the whole JPanel, not just the remaining space.
What parameters could I use to get the desired effect? I know I could use absolute positioning, but I don't want to do that because it defeats the purpose of using MiGLayout in the first place in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找这样的东西吗?
干杯!
Can it be something like this you are looking for?
Cheers!
您可以使用 JXLayer 并将按钮放在玻璃窗格中。
You can use the JXLayer and put the buttons in the glasspane.
创建 JPanel 时,请使用以下 MigLayout 初始值设定项:
new MigLayout("","[]push[center]push[]","")
如果您不了解约束,请查看此处:MigLayout 白皮书
这是假设您在此 JPanel 中没有其他任何内容...
When creating your JPanel, use the following MigLayout initializer:
new MigLayout("","[]push[center]push[]","")
If you don't know about constraints, check here: MigLayout Whitepaper
This is assuming you don't have anything else in this JPanel...