1

I am using org.eclipse.swt.widgets.List to add some items dynamically.

However the size of each string is larger than the default width given by the List.

How do I recompute the size of the list each time I add a new String into the List?

Edit 1
Sorry for the naivety of the question, still a novice to SWT.

This is how I have created it:

Group parentGrp = new Group(threeColComposite,SWT.NONE);  
parentGrp.setText("Interfaces Present in Selected jar");  
parentGrp.setLayout(new GridLayout(1,false));  
parentGrp.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));  
myList = new List(parentGrp, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);  
myList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

I haven't used a separate layout for the list as it was the only child of the parent group. Is it wrong if a layout hasn't been used?

Edit 2
@Baz: I have used the snippet from your answer here from the createMiddleContent() method

Community
  • 1
  • 1
user1422163
  • 145
  • 1
  • 9
  • Do you use a `Layout`? If so which one and which `LayoutData` does your `List` have? If not, why not?? – Baz Oct 27 '12 at 14:58
  • Have you tried calling `myList.pack()` or `parentGrp.layout(true, true)`? – Baz Oct 29 '12 at 11:19

2 Answers2

3

I think the best way is to create your won Custom List (check e.g. http://www.snip2code.com/Snippet/11489/Custom-SWT-List-Box to create such a list) and then manage the events directly inside here

Cristiano Ghersi
  • 1,944
  • 1
  • 20
  • 46
0

The Layout class and its subclasses provide that resizing behavior, albeit indirectly. The layout caches the original size of the list and uses that size even after you add more (and longer) items to the list. The fix is to tell the layout to layout a particular control and its children after flushing its cache (all one layout method). The widget/control you pass in is depends on how many widgets around your list need to be resized becase the list is resized.

Of course, the layout you use must be the same layout that laid out the widgets in the first place.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
  • I couldnt understand the solution. What exactly do you mean by "The fix is to tell the layout to layout a particular control and its children after flushing its cache (all one layout method)" @Baz: Tried `myList.pack()` and `parentGrp.layout(true, true)`. But didn't work. :( – user1422163 Nov 02 '12 at 15:27