2016-10-28 14 views
0

「情報」クラスから「アクティブ」値を取得しようとしていて、ユーザーが編集できるように、チェックボックスとしてTableView Columnに設定しようとしています。私は私のコントローラで、次のしている:ここではTableView列のJavaFX CheckBox値を設定する方法は?

activeColumn.setCellValueFactory(new PropertyValueFactory<Information, Boolean>("Active")); 
      final Callback<TableColumn<Information, Boolean>, TableCell<Information, Boolean>> cellFactory = CheckBoxTableCell.forTableColumn(activeColumn); 
      activeColumn.setCellFactory(new Callback<TableColumn<Information, Boolean>, TableCell<Information, Boolean>>() { 
       @Override 
       public TableCell<Information, Boolean> call(TableColumn<Information, Boolean> column) { 
        TableCell<Information, Boolean> cell = cellFactory.call(column); 
        cell.setAlignment(Pos.CENTER); 
        return cell ; 
       } 
      }); 
      activeColumn.setCellFactory(cellFactory); 
      activeColumn.setEditable(true); 

は、私はアクティブ値がtrueとして取得しています私の「情報」クラスです/ falseの

public Information(Hashtable information) { 
    ::: 

    String strActive = cvtStr(information.get("Active")); 
      if (strActive.equals("1")) 
       this.active = true; 
      else if (strActive.equals("0")) 
       this.active = false; 
} 
public boolean isActive() { 
     return active; 
    } 

    public void setActive(boolean active) { 
     this.active = active; 
    } 

を、私はそれを実行すると、私はチェックボックスが届きません「アクティブ」が真であるところをチェックした。ここではスクリーンショットです:

enter image description here

いずれかが、私は間違ってどこをやっている私に言うだろうか?それともこれを行うための他の方法がありますか?

すべてのヘルプは大幅にあなたのモデルクラスで

答えて

1

使用のJavaFXプロパティいただければ幸いです:あなたは(あなたがどういうわけか二度設定)あなたのセル値工場でエラーが発生している

public class Information { 

    private final BooleanProperty active = new SimpleBooleanProperty(); 

    public Information(Hashtable information) { 

     // ... 

     String strActive = cvtStr(information.get("Active")); 
     if (strActive.equals("1")) 
      setActive(true); 
     else if (strActive.equals("0")) 
      setActive(false); 
    } 

    public BooleanProperty activeProperty() { 
     return active ; 
    } 

    public final boolean isActive() { 
     return activeProperty().get(); 
    } 

    public final void setActive(boolean active) { 
     activeProperty().set(active); 
    } 

    // ... 

} 

注:それが必要に

activeColumn.setCellValueFactory(new PropertyValueFactory<Information, Boolean>("active")); 

良いが、まだ

activeColumn.setCellValueFactory(cellData -> cellData.getValue().activeProperty()); 
012になること
+0

ご返信ありがとうございます。私は試した。動作しません。コントローラーでactiveProperty()を使用する方法を教えてください。多くのお返事を考えてくれてありがとう。 –

+1

@SadequerRahmanああ、あなたのセルバリューファクトリーにエラーがあります。答えを更新しました。 'PropertyValueFactory'は' activeProperty() 'を暗黙的に使います(名前が正しい限り)。とにかくセルバリューファクトリの明示的な実装を使用する方がよいでしょう。それでも問題が解決しない場合は、[MCVE]を作成して質問を編集して含めることをお勧めします。 –

+0

私はもう一度あなたに感謝したいです。期待どおりに機能します。 –

関連する問題