本文介绍了进度条和表格中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to put in a table cell, one label and progressbar.

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

For the progressbar, I was using:

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

但是现在有必要在单元格中有一个超出进度条标​​签,找不到解决方案这个

But now it is necessary to have one beyond progressbar label inside the cell, could not find a solution to this

班级表:

公共班级Tabela {

public class 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;
 }

}

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

While my process is running, you'll have a progressbar in the cell of the table, where the label will change.

我感谢任何帮助..

推荐答案

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

You need to write your own cell factory:

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);

这篇关于进度条和表格中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:43