tags:

views:

116

answers:

1

Hi everyone,

Can someone share how to make items in a ListViewer scrollable? Source code will be more helpful.

Thanks.

A: 

Simply add SWT.H_SCROLL | SWT.V_SCROLL as second argument in the constructor, i.e.

ListViewer v = new ListViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL);

Here is a Snippet - resize the shell to be small enough, and you get scroll bars.

the.duckman
Thanks the.duckman, this works out. ListViewer JavaDoc also says that this the default style for ListViewer (H_SCROLL, V_SCROLL, BORDER and MULTI). But it only works with FillLayout and not with RowLayout or GridLayout! Do you know any reason for this and how to make it work?
Gabriel Parenza
Hard to tell without code. It should work with any layout, it you use the layout properly.
the.duckman
@Gabriel Parenza - if the RowLayout or GridLayout's children don't have properly defined LayoutData then the parent composite isn't able to correctly size the ListViewer, and thus, it doesn't know the scrollbar should appear. You can see this by printing out the bounds of the ListViewer after layout - it will have larger bounds than the visible region. Try setting a GridData with SWT.FILL and expand if you're using GridLayout. Also, if the.duckman's answer is correct you should accept it!
wsorenson