进度条和表格中的标签

时间:2013-08-13 11:36:29

标签: java javafx

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

对于进度条,我正在使用:

@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;
 }

}

当我的进程正在运行时,您将在表格的单元格中有一个进度条,标签将会更改。

我感谢任何帮助..

1 个答案:

答案 0 :(得分: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);