1

我在 GUI Designer 中创建了一个多列表。我将模型设置如下

   @Override
protected boolean initListModelMultiIssueList(List cmp) {
    fetchIssues(cmp);
    if (issueVector != null ) {
    cmp.setModel(new DefaultListModel(issueVector));
    System.out.println(cmp);
    }
    return true;
}
void fetchIssues( List c){
    //fetch issues based on the searchquery hash
    //first thing is to create the query from the hash
    System.out.println("Starting to fetch results");
    try{
        java.util.List<ServiceRequest> serviceRequests = ServiceRequest.getServiceRequests(formQuery(searchQuery),true);
        //we need to now populate the issueVector
        //with the data
        System.out.println(serviceRequests.toString());
        if (issueVector != null ) {
            issueVector.clear();
        } else {
            issueVector = new Vector();
        } 
        int index = 0;
        for (ServiceRequest serviceRequest : serviceRequests) {
                Hashtable hIssue = new Hashtable();
                hIssue.put("id",serviceRequest.getHref());
                //System.out.println(hIssue); 

                ImageDownloadService.createImageToStorage(serviceRequest.getRequestPictureURL().toString(),
                        c, index, "icon", 
                        "service-icon-"+ index ,null);
                //hIssue.put("icon", serviceRequest.getRequestPictureURL().toString());
                //System.out.println(hIssue);
                //reverse geocode the location
                Double x = new Double(0.0);
                x=new Double(serviceRequest.getRequestLocationLatitude());
                Double y = new Double(serviceRequest.getRequestLocationLongitude());
                String location=reverseGeocode(x, y);
                hIssue.put("location", location);
                //System.out.println(hIssue);
                Service service = serviceRequest.loadService();
                hIssue.put("service", serviceRequest.loadService().getName().toString());
                hIssue.put("reportedOn",serviceRequest.getCreatedAt().toString());
                //System.out.println("Final hIssue" + hIssue.toString());
                issueVector.add(hIssue);
                index=index+1;
                System.out.println(issueVector);
        }

    }catch (Exception e){
        System.out.println("Error loading search results");
        System.out.println(e);
    }
}

多列表 GUI 设计中的图标已设置为适当的属性。ImageDownloadService 确实下载了图像文件,但它没有按预期显示在列表中。我究竟做错了什么?

4

1 回答 1

1

可能在条目可用之前下载了图像。虽然很难用代码来判断并且没有对症状的明确解释。

您需要首先创建模型并将其设置到列表中(最好使用空白占位符图像,这样列表就不会“跳跃”)。那么就需要遍历列表并调用图片下载服务,否则可能会在数据还没到列表之前就返回而失败!如果图像已经在缓存中,则可能会发生这种情况,因此在这种情况下它很可能会快速失败。

于 2013-03-15T13:18:20.393 回答