Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ven Rodri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
Venita
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Nigel Westbury
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



Nigel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic