[SOLVED] Need help with adding Spatial to Gui Element using layout

Hi
It’s me again,

Can I use Layouts (like BorderLayout) to centeralize a JME Spatial inside a gui element (for example inside a button) ?

When I tried to do that I got
java.lang.IllegalArgumentException: Child is not GUI element.

this is my test code

I am doing this test inside my cell renderer.

cell is a lemur button and I added a BorderLayout to it.

 Box b = new Box(10, 10, 10); // create cube shape
                spatial = new Geometry("Box", b);  // create cube geometry from the shape
                Material mat = new Material(app.getAssetManager(),
                        "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
                mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
                spatial.setMaterial(mat);

                ((Node)spatialNode).attachChild(spatial);
                BorderLayout layout = cell.getControl(GuiControl.class).getLayout();
                layout.addChild(BorderLayout.Position.Center, (Node)spatialNode);

To participate in a layout, a Spatial will need a GuiControl added to it. You will also have to set a preferred size and so on.

On my to-do list is to write a model component sort of like IconComponent but to hold a spatial as a child. Someone on the forum has done something similar to this already once, I thought.

But in the simple case, adding a GuiControl and setting that control’s preferred size may be enough.

1 Like

Got that working, thank you.
Added a GuiControl and applied an inset component and a border layout.

Glad it’s working.

1 Like