一部の TableView 行の外観を変更するのに苦労しています。線は、ストロークと赤でテキストを表示する必要があります。実際、赤色で表示することはできますが、まだストロークを行うことはできません。これは、行の外観を変更するために使用している css クラスです。
.itemCancelado {
-fx-strikethrough: true;
-fx-text-fill: red;
}
このスタイル クラスは、ユーザーがアイテムをキャンセル済みとしてマークすると追加されます。
public class ItemCanceladoCellFactory implements Callback<TableColumn, TableCell> {
@Override
public TableCell call(TableColumn tableColumn) {
return new TableCell<ItemBean, Object>() {
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? "" : getItem().toString());
setGraphic(null);
int indice=getIndex();
ItemBean bean=null;
if(indice<getTableView().getItems().size())
bean = getTableView().getItems().get(indice);
if (bean != null && bean.isCancelado())
getStyleClass().add("itemCancelado");
}
};
}
}
ここには別の問題があります。キャンセル済みとしてマークされた行は、ユーザーが監視可能なリストに要素を追加または削除したときにのみ色を変更します。TableView を強制的に更新する方法はありますか?
編集された情報
BooleanProperty を使用するように ItemBean クラスを変更したところ、部分的に解決されました。
public class ItemBean {
...
private BooleanProperty cancelado = new SimpleBooleanProperty(false);
...
public Boolean getCancelado() {
return cancelado.get();
}
public void setCancelado(Boolean cancelado){
this.cancelado.set(cancelado);
}
public BooleanProperty canceladoProperty(){
return cancelado;
}
}
残念ながら、「cancelado」列 (これが最終的に機能したときに非表示または削除される) のみが外観を変更します。
ここで、列とテーブルを構成します。
public class ControladorPainelPreVenda extends ControladorPainel {
@FXML
private TableView<ItemBean> tabelaItens;
private ObservableList<ItemBean> itens = FXCollections.observableArrayList();
...
private void configurarTabela() {
colunaCodigo.setCellValueFactory(new MultiPropertyValueFactory<ItemBean, String>("produto.id"));
colunaCodigo.setCellFactory(new ItemCanceladoCellFactory());
colunaDescricao.setCellValueFactory(new MultiPropertyValueFactory<ItemBean, String>("produto.descricao"));
colunaDescricao.setCellFactory(new ItemCanceladoCellFactory());
colunaLinha.setCellValueFactory(new MultiPropertyValueFactory<ItemBean, String>("produto.nomeLinha"));
colunaLinha.setCellFactory(new ItemCanceladoCellFactory());
colunaQuantidade.setCellValueFactory(new PropertyValueFactory<ItemBean, BigDecimal>("quantidade"));
colunaQuantidade.setCellFactory(new ItemCanceladoCellFactory());
colunaValorLiquido.setCellValueFactory(new PropertyValueFactory<ItemBean, BigDecimal>("valorLiquido"));
colunaValorLiquido.setCellFactory(new ItemCanceladoCellFactory());
colunaValorTotal.setCellValueFactory(new PropertyValueFactory<ItemBean, BigDecimal>("valorTotal"));
colunaValorTotal.setCellFactory(new ItemCanceladoCellFactory());
colunaCancelado.setCellValueFactory(new PropertyValueFactory<ItemBean, Boolean>("cancelado"));
colunaCancelado.setCellFactory(new ItemCanceladoCellFactory());
tabelaItens.setItems(itens);
}
...
}
すべての列を更新するにはどうすればよいですか?