Search code examples
javalibgdx

How to add lists to SelectBox in libgdx


I have a selectbox in libgdx , I am trying to add a list of values to it . Is the a way i can add the list such as selectbox.addAll(list1) ?


Solution

  • Due to SelectBox reference the method you are looking for is

        public void setItems(T... newItems)
    

    You can use it for example like this:

        SelectBox.SelectBoxStyle boxStyle = new SelectBox.SelectBoxStyle();
        //creating boxStyle...
    
        String[] values = new String[]{"value1", "value2", "value3", "value4"};
        SelectBox<String> selectBox = new SelectBox<String>(boxStyle);
        selectBox.setItems(values);
    

    Of course instead of creating the style manually you can use Skin with predefined .json file for this purpose