2017-08-11 2 views
1

私はまだJavaFXに慣れていて、工場の仕組みをあまり理解していません。JavaFX 1つのtableRowに対する複数のcellValueFactories?

私がしようとしているのは、String値が何であるかによってtableCol内のtableCellにスタイリングを適用し、セルを編集可能にすることです。

は今の私のコードは次のようになります。

notesColumn.setCellFactory(column -> new TableCell<Computer, String>() { 
     @Override 
     protected void updateItem(String item, boolean empty) { 
      super.updateItem(item, empty); 
      if (item == null | empty) 
      { 
       setText(null); 
       setStyle(""); 
      } 
      else 
      { 
       setText(item); 
       if (item.contains("Restoring @")) setTextFill(Color.CRIMSON); 
       else if (item.contains("Ready")) setTextFill(Color.FORESTGREEN); 
       else setTextFill(Color.BLACK); 
      } 
     } 
    }); 

そして、私はそれにしたいと思い、この作品では動作しますが、私は以下のコードを使用してセルを編集可能にしようとした場合、cellFactoriesは、1を上書きもちろん別のもの。どのように私は2つを組み合わせるのですか?

notesColumn.setCellFactory(TextFieldTableCell.forTableColumn()); 
+0

ちょうどあなたのカスタムセルの実装 'TextFieldTableCell'の代わりに、' TableCell'のサブクラスのサブクラスを作ります。 –

+0

私はそれをどうやって行うのか明確にしてもらえますか?前もって感謝します! –

+0

明確にすることが何であるか分かりませんか? –

答えて

0

次は動作するはずです:

notesColumn.setCellFactory(column -> new TextFieldTableCell<Computer, String>(new DefaultStringConverter()) { 
    @Override 
    public void updateItem(String item, boolean empty) { 
     super.updateItem(item, empty); 
     if (item == null | empty) 
     { 
      setStyle(""); 
     } 
     else 
     { 
      if (item.contains("Restoring @")) setTextFill(Color.CRIMSON); 
      else if (item.contains("Ready")) setTextFill(Color.FORESTGREEN); 
      else setTextFill(Color.BLACK); 
     } 
    } 
}); 
+0

ありがとうございます。それは私が探していたものです! –

関連する問題