How to prevent MigLayout from exceeding a container's bounds

此生再无相见时 提交于 2020-01-23 07:46:38

问题


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?

Thanks


回答1:


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

You can do this by changing the layout for the label to "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.



来源:https://stackoverflow.com/questions/3662768/how-to-prevent-miglayout-from-exceeding-a-containers-bounds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!