问题描述:

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

网友答案:

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

网友答案:

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.

相关阅读:
Top