如何防止MigLayout超出容器的界限 [英] How to prevent MigLayout from exceeding a container's bounds

查看:121
本文介绍了如何防止MigLayout超出容器的界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MigLayout构建一个简单的状态面板,如下所示:

I'm trying to construct a simple status panel using MigLayout as follows:

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?

谢谢

推荐答案

尝试将标签的最大宽度设置为100%。

Try setting the maximum width of the label to 100%.

您可以通过将标签的布局更改为span 2,换行,wmax 100%

You can do this by changing the layout for the label to "span 2, wrap, wmax 100%"

在我的测试中,我发现它看起来仍然不太合适,所以你可能想减去一点点长度(类似 wmax 100% - 10px ),使它远离边缘。

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.

这篇关于如何防止MigLayout超出容器的界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆