Call getItemHeight Multiply the result by the number of items you wish to see displayed to get a height Call computeSize with the height you just calculated (probably set width to default) Call setSize with the Point returned by computeSize
Doesn't seem very straight-forward but was the only thing I could come up with looking at the API. There's probably an easier way.
Is there a compelling reason you need to show a set number of items versus just letting the List default to what it wants to show?
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
John is right to question why you are trying to override the default behavior. However the List control has a preferred size which is the size needed to contain all the items without the need to scroll. This can look quite silly when there are a large number of items.
Controlling the sizes of controls in SWT is better done by the container than by the control itself. This is logical because the best size of the list really depends more on the layout that is using the list than on the list itself. If you are using the list inside a composite with RowLayout, for example, then you can set the height by something like:
subject: org.eclipse.swt.widgets.List - how to set visibile row count?