删除 MigLayout 中的 JButton 填充
我有一个像这样的小“弹出窗口”:
但我不想要按钮周围的填充,我想要它与所提供的文本一样小。
btn.setMargin(new Insets(1, 1, 1, 1));
panel.add(lbl, "wrap");
panel.add(btn);
frame.pack();
frame.setVisible(true);
至少这行不通…… 这可以在 MigLayout 上实现吗?或者我应该为此框架使用其他布局管理器。
I have a small "popup" like this:
But I don't want the padding around the button, I want it to be as small as it can be with the supplied text.
btn.setMargin(new Insets(1, 1, 1, 1));
panel.add(lbl, "wrap");
panel.add(btn);
frame.pack();
frame.setVisible(true);
At least this doesn't work...
Can this be achieved on MigLayout or should I use some other layout manager for this frame.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您构建它时使用的
MigLayout
约束是什么?如果您还没有尝试过,您可能想尝试使用novisualpadding
。此外,debug
布局约束将在组件周围绘制方框以显示它们占用的空间。 (我认为红色虚线是组件的大小,蓝色虚线是组件所在的“单元格”。)我经常使用 MigLayout,并发现“备忘单”非常有用。 http://migcalendar.com/miglayout/cheatsheet.html
What's your
MigLayout
constraints that it was built with? You might want to try usingnovisualpadding
if you aren't already. Also, thedebug
layout constraint will draw boxes around your components to show what room they take up. (I think the red dotted lines are the size of the components and the blue dotted lines are the "cells" that the component is in.)I use MigLayout pretty often and have found the "cheat sheet" pretty useful. http://migcalendar.com/miglayout/cheatsheet.html
布局管理器不应该影响组件的绘制方式。
使用 Metal LAF 时,setMargin(...) 对我来说效果很好。也许您的 LAF 不支持 setMargin() 方法。或者也许您在其他地方有一些代码覆盖了按钮的首选大小,导致它像这样绘制。
但是,如果 MIG 布局出现问题,您可以尝试 换行布局。
A layout manager should not affect the way a component is painted.
The setMargin(...) works fine for me when using the Metal LAF. Maybe your LAF doesn't support the setMargin() method. Or maybe you have some code elsewhere that is overriding the preferred size of the button causing it to paint like this.
However, if the MIG layout turns out to be the problem, you could try the Wrap Layout.
以 MIke 的回答作为初创公司,我在 MIG“CheatSheet”中找到了解决您问题的可能解决方案。
设置 MIGLayout 时,可以使用定义列和行的方括号之间的整数指定组件之间的间隙。
例如
Taking MIke's answer as a startup, I found in the MIG "CheatSheet" a possible solution to your problem.
When you set up a MIGLayout, you can specify the gap between component with an integer between the square brackets defining columns and rows.
E.g.
我刚刚也遇到这个问题了。我发现以下方法对我有用:
或者
在使用物质外观和感觉时,有一个功能,即最小尺寸总是太宽。这可以用这个不起眼的 hack 来覆盖。
I've just been having this issue too. I discovered that the following worked for me:
or
Also when using the substance look and feel there is a feature where the minimum size is always too wide. This can be overridden with this obscure hack.