Well, first you are using attachChild() instead of addChild() so it’s just adding it like any other spatial and its not involved in the layout at all.
…it’s not clear what you intend to do with the slider so I can’t answer further than that. The above is why it doesn’t layout with the rest of the elements.
If you are trying to make a container that only shows some of your buttons with a slider to move up and down then this will not work. You should use a list box instead.
JME does not provide the facilities for Lemur to create a scroll pane. It’s just simply impossible. You can fake it with viewports and stuff but not in a way that a Lemur component could do on its own.
But for your use case, it seems like you want a list box… which is already a scrollable list of buttons.
For the future, you probably need to think about and understand how layouts work in Lemur. There are numerous examples in the Lemur demos.
The list box is already made of buttons. You don’t have to add buttons.
I don’t have time to step-by-step take you through every line of code today. You are going to have to look at the demos and examples and try to figure things out a little on your own.
public class ListBoxItem {
public String text;
public ListBoxItem(String text){
this.text = text;
}
public String toString(){
return text;
}
public void action(){
}
}
and add to list box
for( int i = 0; i < 10; i++ ) {
listBox.getModel().add(new ListBoxItem("Item " + i));
}
public class ListBoxItem {
public String text;
public ListBoxItem(String text){
this.text = text;
}
public String toString(){
return text;
}
public void action(){
System.out.println("Click " + text);
}
}
monstersWindow = new Container();
monstersWindow.setLocalTranslation(widnth/2, height/2, 10);
ListBox listBox = new ListBox();
for( int i = 0; i < 10; i++ ) {
listBox.getModel().add(new ListBoxItem("Item " + i));
}
listBox.addClickCommands(new Command() {
@Override
public void execute(Object source) {
ListBox list = (ListBox) source;
ListBoxItem boxItem = (ListBoxItem) list.getSelectedItem();
boxItem.action();
}
});
listBox.setVisibleItems(6);
listBox.setPreferredSize(new Vector3f(200, 200, 0));
listBox.setLocalTranslation((800) , 680, 0);
monstersWindow.addChild(listBox);
In Java there are these things called “generic types”. If you use them properly then in some cases you can avoid casting. The command is one such case: