Lemur listbox scroll bars

Intuitively, I would think creating a ListBox and setting the visible items to a number would mean that scrollbars would only show if the number of items in the list were to exceed that number. Intuitively, I would expect just creating a ListBox with any number of items would just expand the ListBox, with no scrolling. Instead, they appear always and I am struggling to find any way for there not to be scroll bars.

Evidently, my expectations are not realistic and most probably I am missing something.

So does this mean to create a simple list of clickable items without scrollbars, I have to use panel, container, layout and labels with a click listener?

A ListBox is a GridPanel with a scroll bar and selection. As you describe, it’s not hard to roll your own thing without a scroll bar… it’s not even really as hard as you say since all of the things ListBox uses are also available to you.

The idea of a list box that sometimes expands and sometimes has a scroll bar is a concept that is very popular with UI libraries that do iterative layout. Try this layout, ask every component if it’s ok, adjust a little, repeat… 50 times if necessary, until the layout resolves.

Lemur is a one-pass layout. Ask everything their preferred sizes, lay everything out within the outer constraints provided. As such, it’s important to have components that know their size (like ListBox). So it seems unlikely that there is a workable solution to make ListBox auto-expanding. Not sure how it would even decide to stop expanding (see iterative layout thing above).

There probably could be a solution that would show/hide the scroll bar if the view size was bigger than the number of items displayed. It would require coordination at the ListBox level.

And as to this specifically, if you just want a bunch of clickable things in a panel, I’d personally use Buttons and let them share the same click command. You could wrap that in a container subclass or something… depending on how ‘ugly’ it ends up being to do it in place. (Often times these are filled by a loop anyway.)

Or is it a case where you have a List model that you want to populate the panel from? You could use GridPanel directly in that case. Your adapter from item to cell could manage the click listener bit.

Or do you mean the other way: when something makes the layout bigger/smaller you want the number of items to grow/shrink accordingly?

If so then I think that’s just a missing feature, really. With the caveat that there is no real clipping so what’s displayed in the list will always be an even number of items… it should be possible to autocalculate the number of displayed items and adjust the internal GridPanel size accordingly.

I see what your saying. I can see how Lemur works for static lists.

Not presently. I think for Dynamic, a DefaultListModel as in swing would be nice.

I like the methods that JList, JScrollPane and DefaultListModel provides but am not familiar enough with Lemur to know if that already exists.

I was just looking for a quick way to basically create a JList.

Edit: Pain text rather than having a visible button.

Buttons are plain text by default. Only the style gives them a button-like border.

I am about to dive into styles.

Just in case you haven’t already found it:

And the listbox, scrollbar, etc. are pretty good examples of giving components element IDs that make them stylable in different ways.