简体   繁体   English

如何防止MigLayout超出容器的界限

[英]How to prevent MigLayout from exceeding a container's bounds

I'm trying to construct a simple status panel using MigLayout as follows: 我正在尝试使用MigLayout构建一个简单的状态面板,如下所示:

setLayout(new MigLayout("fillx", "[][p]")); // removing constructor args makes no difference
add(createStatusLabel(), "span 2, wrap");
add(createProgressBar(), "growx, pushx");
add(createCancelButton(), "");

This works fine as long as the status message displayed by the status label is short enough to fit within the current panel's size (the cancel button remains right-justified, and the progress bar resizes to take up the remaining space). 只要状态标签显示的状态消息足够短以适合当前面板的大小(取消按钮保持右对齐,并且进度条调整大小以占用剩余空间),这样就可以正常工作。 If the status message is too long, it is not cropped, and causes the area to exceed the bounds of the container, resulting in the cancel button being pushed off screen. 如果状态消息太长,则不会裁剪,并导致该区域超出容器的边界,导致取消按钮被推离屏幕。

Any suggestions on how to prevent this from happening? 有关如何防止这种情况发生的任何建议?

Thanks 谢谢

Try setting the maximum width of the label to 100%. 尝试将标签的最大宽度设置为100%。

You can do this by changing the layout for the label to "span 2, wrap, wmax 100%" 您可以通过将标签的布局更改为"span 2, wrap, wmax 100%"

In my tests, I found that it still didn't look quite right, so you may want to subtract a little bit of length (something like wmax 100% - 10px ) to bring it away from the edge. 在我的测试中,我发现它看起来仍然不太合适,所以你可能想要减去一点长度(比如wmax 100% - 10px )以使它远离边缘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM