Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent MigLayout from exceeding a container's bounds

Tags:

java

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?

Thanks

like image 960
zorgbargle Avatar asked Sep 07 '10 21:09

zorgbargle


1 Answers

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.

like image 152
deterb Avatar answered Oct 11 '22 01:10

deterb