2017-03-01 7 views
0

TableCellのupdateItem()メソッドはいつ呼び出されますか? そのセルに関連付けられているプロパティが変更されますか?javafx TableCellクラスのupdateItem()メソッド

私のアプリケーションでは、提供されたハイパーリンクに基づいてコンテンツをダウンロードするスレッドがあります.2つの異なる列にダウンロードの名前と進行状況を表示するTableViewがあります。進行状況の列に、プログレスバーとラベル私はProgressbar and label in tablecellから助けを得ました。しかし、updateItem()メソッドは 'progress'変数を読み取っておらず、-1が毎回読み込まれているようです。ダウンロードクラスのrunメソッドで

Progress.setCellValueFactory(new PropertyValueFactory<Download, Double>("progress")); 
     Progress.setCellFactory(new Callback<TableColumn<Download, Double>, TableCell<Download, Double>>() { 
      @Override 
      public TableCell<Download, Double> call(TableColumn<Download, Double> param) { 
       return new TableCell<Download, Double>(){ 
        ProgressBar bar=new ProgressBar(); 
        public void updateItem(Double progress,boolean empty){ 
         if(empty){ 
          System.out.println("Empty"); 
          setText(null); 
          setGraphic(null); 
         } 
         else{ 
          System.out.println(progress); 
          bar.setProgress(progress); 
          setText(progress.toString()); 
          setGraphic(bar); 
          setContentDisplay(ContentDisplay.GRAPHIC_ONLY); 
         } 
        } 
       }; 
      } 
     }); 

私のダウンロードクラスのADT

public class Download extends Task<Void>{ 
    private String url; 
    public Double progress; 
    private int filesize; 
    private STATE state; 
    private Observer observer; 
    public Object monitor; 
    private String ThreadName; 
    private int id; 

    public static enum STATE{ 
     DOWNLOADING,PAUSE,STOP; 
    } 
    public Download(String url,Observer observer,Object monitor){ 
     this.url=url; 
     this.observer=observer; 
     this.monitor=monitor; 
     progress=new Double(0.0d); 
    } 

私は継続的にそれにダウンロードされたバイト数を追加することによって、「進捗状況」変数を更新しています。

答えて

1

Taskにはprogressというプロパティがありますが、追加した進捗フィールドに書き込むと変更されません。 (PropertyValueFactoryは、結果を取得するためのメソッドを使用していないフィールドとDoubleフィールドはとにかくそれを観察する方法はありません。)

updateProgressは、プロパティが適切にアプリケーションスレッドと同期していることを確認するために、このプロパティを更新するために使用する必要があります。

public class Download extends Task<Void>{ 

    protected Void call() { 

     while (!(isCancelled() || downloadComplete())) { 

       ... 

       // update the progress 
       updateProgress(currentWorkDone/totalWork); 
     } 

     return null; 
    } 

} 
関連する問題