在java中使用SWT中的进度条

时间:2017-05-11 06:56:14

标签: java swt

实际上我正在使用线程来更新代码块中的进度条,线程的运行方法不起作用,所以,请你帮我解决问题。我正在使用SWT工具包进行用户界面。 />         代码:

//选择监听器

    tItem.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) 
                        {
             TableItem[] tableItems =table.getItems();
                        int c=0;
                int inty=table.getSelectionIndex();
                  for(int i=table.getSelectionIndex();i<tableItems.length;i‌++)
                   {    
                        if(c==0)
                        {
                          column = new TableColumn(table, SWT.CENTER);       
     //reading content from the table        Stringline=tableItems[i].getText(0)+","+tableItems[i].getTex‌t(1)+","+tableItems[‌​i].getText(2)+","+ta‌​bleItems[i].getText(‌​3)+","+tableItems[i]‌​.getText(4)+","+tabl‌​eItems[i].getText(5)‌​+","+tableItems[i].g‌​etText(6);
                         System.out.println("\n line value is "+line);
                        String split= ",";
                        String error=",,,,,,";
                        if(line.equals(error))
                        {
                        break;
                        }
                    else {while ((line!= null))
                    String[]com = line.split(split,20);
                    String result =null;
//checking whether the value in it is enable or n
                    if(com[0].contains("ENABLE"))
                    { result = "RESULTS"; 
                    continue;}
                    if(com[0].equals("N"))
                    {result = "No";} 
                    else if(com[2].startsWith("S=") )
                    {
                     String O=tableItems[i].getText(7);
                     String[] part = O.split("=");
                     String string2 = part[1];
                     a=Integer.parseInt(string2);
    //declaration of the thread
                     final Thread thread = new Thread()
                    {public void run() 
                    {for(int i=0; i<=a; i++) 
                    {
                    final int value = i;
                    try {
                    Display.getDefault().asyncExec(newRunnable() 
                    {
                        public void run() 
                    { 
    //assigning value to the progress bar
    pbar.setSelection(value);
                    }
                    });
                    }   
                    catch (Exception e) 
                    {
                    System.out.println("Warning");
                     } 
                    } 
                    }
                    thread.start(); 
                    inty++;
                    break;
                    }
    }
    });

0 个答案:

没有答案