[Lemur] How to set panel size?

This mostly goes to @pspeed, but maybe somebody else has a hint as well.
Maybe Lemur refuses to handle that because it’s better handled outside of Lemur, maybe I’m just trying the wrong approach inside Lemur - any insight on the right approach appreciated.

I’m trying to create a panel with a fixed size (600 x 400 or something like that) at the center of the screen. It’s supposed to serve as the backdrop for the start-of-game GUI (configuration, game file loading/saving, that kind of stuff).
Right now, it all works, except it insists on resizing itself to fit the controls inside, instead of to 600x400. Trying to setPreferredSize just gave me an NPE in SpringGridLayout.

Here’s what I’m doing:
[java] Container backgroundPanel = new Container();
backgroundPanel.setLocalTranslation(x, screenH - y, 0);
// this crashes because SpringGridLayout#rowPrefs is null
backgroundPanel.setPreferredSize(new Vector3f(w, h, 0));

    new QuadBackgroundComponent(
        new ColorRGBA(0.5f, 0f, 0f, 0.5f),
        5f, // xMargin
        5f, // yMargin
        1f, // zOffset
        false // lit

Container panel = new Container();
panel.addChild(new Label ("Blah", new ElementId("blah"), null));


Exception stack trace:
[java]152155 [LWJGL Renderer Thread] ERROR com.jme3.app.Application - Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]
at com.simsilica.lemur.component.SpringGridLayout.distribute(SpringGridLayout.java:315)
at com.simsilica.lemur.component.SpringGridLayout.reshape(SpringGridLayout.java:329)
at com.simsilica.lemur.core.GuiControl.setSize(GuiControl.java:141)
at com.simsilica.lemur.core.GuiControl.revalidate(GuiControl.java:307)
at com.simsilica.lemur.core.GuiControl.controlUpdate(GuiControl.java:273)
at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:112)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at org.durchholz.jme3lib.ClientApplication.update(ClientApplication.java:311)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:229)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)

I think there is some weirdness here that I never tracked down. (All of my real GUIs are self-sizing and I haven’t added a forced size panel to the demo yet.) Just in case, be sure you are running the latest code (though the stack traces are right anyway).

There is a bug I see in SpringGridLayout that if the preferred size is never calculated at least once then it will NPE. I need to fix that.

In the mean time, before forcing preferred size ask the panel what it’s preferred size is. You can throw away the value but it will cause it to at least run through one calculation. That should at least get you to the next problem if there is one.

It could be the setSize() is hitting a different problem in that it isn’t forcing validation of the components… ie: they have to have been auto-laid out once before setSize() will work. It could just be broken right now.

setSize() and setPreferredSize() are supposed to work (perhaps a little differently) but I know there are issues right now. If I get time soon then I will track this down.

setPreferredSize() for SpringGridLayout panels is fixed to work in SVN now. The BasicDemo also illustrates the functionality now.

In theory, this should fix setSize() also but I didn’t test it.

Edit: and in general, setPreferredSize() is probably safer just in case something causes the component to get revalidated later.

1 Like

Sweet - worked right out of the box via setPreferredSize.
Thanks a lot!

@toolforger said: Sweet - worked right out of the box via setPreferredSize. Thanks a lot!

Yay. Glad to have independent confirmation. :slight_smile: