Depending on the layout of the container, it may always force the size on the components. Even in the case of setting the preferred size, the container may only take that as a suggestion (depending on the layout’s needs).
There are a couple ways to do what you want, I think.
From your description, you essentially want a block box with a green growing box inside of it. So first, we’ll create a container with a black background: (I’ve presumed horizontal.)
[java]
Container test = new Container();
test.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
[/java]
…now the trick is to have a child that is only ever the size you want it. The most direct way:
[java]
// Give the container a layout that will not stretch the children at all in the x direction
test.setLayout(new SpringGridLayout(Axis.Y, Axis.X, FillMode.Even, FillMode.None);
[/java]
Now the size of the children (at least in Axis.X) will be whatever you set them to. (Might have to set preferred size vs. size, I don’t remember for sure)
[java]
Panel bar = test.addChild(new Panel(75, 15, ColorRGBA.Green));
bar.setPreferredSize(new Vector3f(progressAmount, 15, 0)); // or whatever
[/java]
However, if you do it that way then you must also do the calculations yourself for 100% of width and so on. Here you could also get away with letting Lemur do that work for you by using dynamic insets. These will set the top, left, bottom, right insets based on the size of the component.
[java]
Container progress = new Container(new BorderLayout());
progress.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
Panel bar = progress.addChild(new Panel(0, 15, ColorRGBA.Green));
bar.setPreferredSize(new Vector3f(0, 15, 0));
// Presuming “precent” is 0 to 1.0 value
DynamicInsetsComponent progressInsets = new DynamicInsetsComponent(0, 0, 0, percent - 1.0);
bar.setInsetsComponent(insets);
// Then if you want to change it:
progressInsets.setInsets(new Insets3f(0, 0, 0, percent - 1.0));
[/java]
That way if you put the “progress” component into some other layout it can be resized and the progress indicated will still be accurate as a percentage of width if that makes sense. Note: the ‘dynamic insets’ are calculated as a percentage of “extra size”. So if the layout wants to make the component 500 width but the component naturally only wants to be 100 wide then the left/right values of dynamic insets will control how it partitions that extra 400 units.
Because I set the preferred size to 0 width, then the size of the child will be 100% controlled by this extra space. Without any insets, the child will want to be the full size of the container. We add insets to the right (percent - 1.0) to take up the full extra space when the percent is 0 and none of the extra space (ie: child will fill the whole space) when percent is 1.