Hello. I’m trying to design a simple GUI with Lemur: caption and two fields with labels.
//create window
this.optWindow = new Container();
optWindow.setLayout(new BoxLayout(Axis.Y, FillMode.None));
optWindow.setLocalTranslation(leftLocationOptWindow, topLocationOptWindow, 0);
//label
optWindow.addChild(new Label("Options"));
//first
com.simsilica.lemur.Container Dim1Panel = new com.simsilica.lemur.Container();
Dim1Panel.setLayout(new BoxLayout(Axis.X, FillMode.Last));
com.simsilica.lemur.Label fieldDim1Label = new com.simsilica.lemur.Label("Field Dim 1");
fieldDim1Text = new com.simsilica.lemur.TextField("");
Dim1Panel.addChild(fieldDim1Label);
Dim1Panel.addChild(fieldDim1Text);
optWindow.addChild(Dim1Panel);
fieldDim1Text.setSize(new Vector3f(30f, fieldDim1Text.getSize().y, fieldDim1Text.getSize().z));
//second
com.simsilica.lemur.Container Dim2Panel = new com.simsilica.lemur.Container();
//text field would not even appear with FillMode.None
Dim2Panel.setLayout(new BoxLayout(Axis.X, FillMode.Last));
com.simsilica.lemur.Label fieldDim2Label = new com.simsilica.lemur.Label("Field Dim 2");
fieldDim2Text = new com.simsilica.lemur.TextField("");
Dim2Panel.addChild(fieldDim2Label);
Dim2Panel.addChild(fieldDim2Text);
optWindow.addChild(Dim2Panel);
fieldDim2Text.setSize(new Vector3f(30f, fieldDim1Text.getSize().y, fieldDim2Text.getSize().z));
It is clearly seen that textfields appear beyond their parents’ border. And with text entry a some left margin appears.
I have supposed that layouts here work similar to analogs from Swing. Am I missing something?
I think the BoxLayouts aren’t working like you want. Just leave them out and let the default SpringGridLayout work for you.
With your current approach, you will also have the problem that your columns won’t line up.
Make one container and add the Options label and another container to it…
Container window = new Container();
Container form = window.addChild(new Container());
// Then for each row you in the "form":
form.addChild(new Label("My Label")); // automatically adds a new row
myTextField = form.addChild(new TextField(""), 1); // the ending 1 will put it in the second column of the current row
You could also do it all explicitly stating each row and column but that’s a pain.
You can see any of a half-dozen examples of this in various pieces of my open source code.
If you search around in these projects you are bound to find hundreds of examples:
Thank you. Your idea is nice, it is used in Examples/MainMenuState.java at master · Simsilica/Examples · GitHub (in initialize() routine, declaring connection port and host interface elements). But when I declare an empty textfield (without any preset text), it does not display on screen. Here is the code:
optWindow.setLocalTranslation(leftLocationOptWindow, topLocationOptWindow, 0);
optWindow.addChild(new Label("Options"));
com.simsilica.lemur.Label fieldDim1Label = new com.simsilica.lemur.Label("Field Dim 1");
fieldDim1Text = new com.simsilica.lemur.TextField("");
optWindow.addChild(fieldDim1Label);
optWindow.addChild(fieldDim1Text, 1);
//not working (no onscreen change)
fieldDim1Text.setSize(new Vector3f(30f, fieldDim1Text.getSize().y, fieldDim1Text.getSize().z));
com.simsilica.lemur.Label fieldDim2Label = new com.simsilica.lemur.Label("Field Dim 2");
fieldDim2Text = new com.simsilica.lemur.TextField("");
optWindow.addChild(fieldDim2Label);
optWindow.addChild(fieldDim2Text,1);
//not working
fieldDim2Text.setSize(new Vector3f(30f, fieldDim2Text.getSize().y, fieldDim2Text.getSize().z));
Here is the screen:
It works good when I add some preset text to it.
Yes… because the preferred size for an empty text field is 0 width. You can set the preferred width or the preferred size and then it will adjust accordingly. See the javadocs.
The javadoc has the methods but not a description. I just meant that you could find the actual method name and figure out how to call it from the javadoc.
Glad you fixed your issue… and I think your newer approach looks better, too.