Question

I have developed an eclipse plugin with few wizard pages. In one of the pages, am using org.eclipse.swt.widgets.List

My code goes as follows:

public void createControl(Composite parent){
    // few lines of code
    List classesList = new List(someComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    if(hugeList!=null) {
        for (int j = 0; j < hugeList.size(); j++){
            String a= hugeList.get(j);
            classesList.add(a);
            System.out.println("Inside loop: " + classesList);
        }
        System.out.println("Outside loop: " + classesList);
    }
    classesList.addListener(SWT.Selection, this);
    // lines of code
}

Here, based upon the size of hugeList the Inside loop: keeps printing the data. But, for Outside loop: the list is empty :(

I couldn't understand the reason. Can someone please help.

Était-ce utile?

La solution

I think the answer here lies in the way that you've attempted to print the information. System.out.println("Outside loop: " + classesList) will implicitly call classesList.toString(). SWT widgets' toString() methods (unless otherwise overridden) form the general pattern:

ClassName {otherInformation}

However, it is up to subclasses to fill otherInformation with useful data by overriding org.eclipse.swt.widgets.Widget.getNameText(). List doesn't do this, so otherInformation is simply the empty string, and toString() will always[1] return List {}.

To get the information from that List that you require, call getItems().

[1] unless it is disposed or is called on the wrong thread.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top