Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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

Ven Rodri
Greenhorn

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?

Thanks,
Venita
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1441
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
Greenhorn

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:



Nigel
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: org.eclipse.swt.widgets.List - how to set visibile row count?
 
Similar Threads
ArrayList.Contains always return true, even the objects are not equal
How to remove duplicate element from List
set two view in expandable list child
SCJP exam Classes & Interfaces
Lock wait timeout exceeded