File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes org.eclipse.swt.widgets.List - how to set visibile row count? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "org.eclipse.swt.widgets.List - how to set visibile row count?" Watch "org.eclipse.swt.widgets.List - how to set visibile row count?" New topic

org.eclipse.swt.widgets.List - how to set visibile row count?

Ven Rodri

Joined: Jun 21, 2002
Posts: 4
I am using an SWT List (org.eclipse.swt.widgets.List) and need a way to set the height of the list to say 10 items.

JList has a method setVisibleRowCount(int). What can I do to achieve this same effect?

John Wetherbie

Joined: Apr 05, 2000
Posts: 1449
Based on the javadoc you might try:

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?

Good luck!

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Nigel Westbury

Joined: Mar 03, 2006
Posts: 1
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:

I agree. Here's the link:
subject: org.eclipse.swt.widgets.List - how to set visibile row count?
It's not a secret anymore!