1

我需要放入一个表格单元格、一个标签和进度条。

对于进度条,我使用的是:

@FXML
private TableView tableView;

@FXML
private TableColumn columTabela;

@FXML
private TableColumn columSituacao;   

private List<Tabela> lista = new ArrayList<Tabela>();

public List<Tabela> getLista() {
    return lista;
}

public void setLista(List<Tabela> lista) {
    this.lista = lista;
}

   private void test() {

    getLista().add(new Tabela("test", -1.0));
    getLista().add(new Tabela("test1", null));
    columTabela.setCellValueFactory(new PropertyValueFactory<Tabela, String>("nome"));
    columSituacao.setCellValueFactory(new PropertyValueFactory<Tabela, Double>      ("progresso"));
    columSituacao.setCellFactory(ProgressBarTableCell.forTableColumn()); 
    tableView.getItems().addAll(FXCollections.observableArrayList(lista));

但是现在有必要在单元格内有一个超越进度条的标签,找不到解决方案

班级表:

公共课 Tabela {

private String nome;

private Double progresso;

public Tabela(String nome, Double progresso) {
    this.nome = nome;
    this.progresso = progresso;
}

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

public Double getProgresso() {
    return progresso;
}

public void setProgresso(Double progresso) {
    this.progresso = progresso;
 }

}

当我的进程正在运行时,表格的单元格中会出现一个进度条,其中的标签会发生变化。

我很感激任何帮助..

4

1 回答 1

3

您需要编写自己的单元工厂:

Callback<TableColumn<Tabela, Double>, TableCell<Tabela, Double>> cellFactory =
    new Callback<TableColumn<Tabela, Double>, TableCell<Tabela, Double>>() {
public TableCell call(TableColumn<Tabela, Double> p) {
    return new TableCell<Tabela, Double>() {

        private ProgressBar pb = new ProgressBar();
        private Text txt = new Text();
        private HBox hBox = HBoxBuilder.create().children(pb, txt).alignment(Pos.CENTER_LEFT).spacing(5).build();
        @Override
        public void updateItem(Double item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                pb.setProgress(item);
                txt.setText("value: " + item);
                setGraphic(hBox);
                setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            }
        }
    };
}
};

然后使用它,

columSituacao.setCellFactory(cellFactory);
于 2013-08-14T13:37:58.217 回答