0

我发现“刷新”我的表格视图的唯一方法是:

private void refreshTable() {
    tableView.getItems().clear();
    try {
        Thread.sleep(Etapa.SLEEP);
        tableView.getItems().addAll(getList());
    } catch (InterruptedException e) {
        Thread.interrupted();
    }
}

但似乎“进度条”无法正常工作:

p.getTableColumn().setVisible(false);
p.getTableColumn().setVisible(true);

有一个更好的方法吗?

我试过这些例子:

JavaFX 2.1 TableView 刷新项

4

1 回答 1

0
columSituacao.setCellValueFactory(new Callback<CellDataFeatures<Tabela, Tabela>, ObservableValue<Tabela>>() {
        public ObservableValue<Tabela> call(CellDataFeatures<Tabela, Tabela> p) {
            return new ReadOnlyObjectWrapper<Tabela>(p.getValue());
        }
    });

    columSituacao.setCellFactory(new Callback<TableColumn<Tabela, Tabela>, TableCell<Tabela, Tabela>>() {
        public TableCell<Tabela, Tabela> call(TableColumn<Tabela, Tabela> param) {

            final ProgressBar progressBar = new ProgressBar();

            final HBox box = new HBox();
            box.setPrefHeight(Progress.PREF_HEIGHT);

            final Text text = new Text();

            BorderPane border = new BorderPane();
            border.setTop(text);
            border.setBottom(progressBar);
            BorderPane.setAlignment(text, Pos.CENTER);

            box.getChildren().add(border);

            return new TableCell<Tabela, Tabela>() {

                @Override
                protected void updateItem(Tabela item, boolean empty) {
                    super.updateItem(item, empty);

                    if (empty) {
                        setText(null);
                        setGraphic(null);
                    } else {
                        if (text != null) {
                            text.textProperty().bind(item.etapaProperty());
                        }
                        progressBar.progressProperty().bind(item.progressProperty());
                        progressBar.prefWidthProperty().bind(this.widthProperty());
                        setGraphic(box);
                        setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                    }
                }
            };
        }

    });

    tableView.getItems().addAll(lista);
    tableView.getSelectionModel().selectFirst();
}
于 2013-08-27T13:47:45.447 回答