How to change height of items in listBox?

1-how to change height of items in listBox?
2-and how can I change font size and font of its text?
3-is it possible to use a Container in list box instead of string?

The items in the list box are built by the cell renderer. The default just converts strings to labels… but you can convert any list of objects to any visual you like.

1 Like

and for changing height of items?

It should be based on the preferred size of the items. Edit: I mean whatever visual element the cell renderer is returning’s preferred size.

1 Like

I tried to change height of cell but it does not work:

Listbox.setCellRenderer((Object t1, boolean bln, Panel pnl) -> {
                    pnl.setPreferredSize(new Vector3f(100, 20, 0));
                    Container con = new Container();
                    Button b = new Button(t1.toString());
                    con.addChild(b);
                    return con;
                });

what is the meaning of that boolean bln?

Selected. So you can change colour on selection or whatever.

no, I need to set height of the items in list box to smaller size.

I know it’s unfortunate that the CellRenderer documentation is not fleshed out, but it at least does give the parameter names:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/LemurProto/com/simsilica/lemur/list/CellRenderer.html

…the issue is you are setting the preferred size on the “maybe pre-existing, maybe not” panel before you then return your own that you’ve given no preferred size to… that will replace existing.

Also, do you plan to add more things to that container? Else you could have just returned the button directly. Just in case that wasn’t clear.

I don’t understand how to resize the items…

yes

Renamed some things to make it clearer and added comments…

You can set the preferred size if you set the preferred size on the container… since that will actually be used.

What is it that you will be displaying in the list? And why is its automatic preferred size not big enough?

…because for example, giving your container insets or whatever might be enough also.

1 Like

I would also like to interfere, as I have modified Lemur myself and might give you an other approach.

Generell: Listbox is a composition of a few elements. One of it is the Gridpanel (link)

The “items in listbox” actually are items of the grid. If you are able to get the grid you can get each element inside and change its value (hint: listbox.getGridPanel().getCell()). Unfortunately you need to do that for all desired elements. I modified the gridPanel so I can change the Layout.

listbox.getGridPanel().setLayout(new SpringGridLayout(Axis.Y;Axis.X,FillMode.ForcedEven,FillMode.Even));

I also added functionality to change the width of the columns and it would be possible to change the height as well.

In your case you could get one element and change its height. The Springgridlayout of grid in Listbox is set to ForcedEven so all elements are forced to have the same size. See if this is enough or if you have to set the size of listbox items as explained by pspeed etc.

  1. Fonts and size of all items could be changed via Style (or element by element via the grid).
    I did it like that:
//      Listbox ITEM labels
        id = new ElementId("list").child("item");
        attrs = style.getSelector(id,"OSG");
        //    attrs.set("color", labelcolor,true);
        attrs.set("color", new ColorRGBA(ColorRGBA.LightGray),true);
        //     attrs.set("font",getApplication().getAssetManager().loadFont("Fonts\\Germania/GermaniaOne.fnt"));
        attrs.set("font",fontGermania);
        attrs.set("fontSize", 25);
  1. Yes, but I think you would need to change lemur source and in my mind it would make no sense.

See here in WIP of January how it looked after the Font and Font Size of listbox is changed. Note that the picture shows my modified listbox with multiselect and multicolumn (link)

I cant find setLayout() method i GridPanel…
your modified lemur GUI lib, is it open source?

Read here, I made it once public .
I am using my own lemur version and from time to time I copy my changed class into that repository. You can have a look and see if it is usefull for you but you might need to change the lemur jars by yourself. And I am repeating myself by saying: I am not an IT guy, so architecture and naming conventions may look weird.
For layout I have added this to GridPanel.java

    public void setLayout(SpringGridLayout lay) {
        this.layout = lay;
        getControl(GuiControl.class).getLayout().clearChildren();
        getControl(GuiControl.class).setLayout(layout);

        this.modelRef = null;
        if( this.model != null ) {
            this.modelRef = model.createReference();
            refreshGrid();
        }

    }

and some more

To OP, I’m still curious about the effect you are trying to achieve. It may be the case that extreme measures are unnecessary. It may also be something that can be changed in a simple way.

Aufricer’s requirements may have been more than you need. It’s hard to say.