Authenticate rows in a TableView from a model

I was looking for information about updating data in a table format. I tried to change the model directly, but I get an error. I am changing the model, but the table is not updated, only when I move the column, the table shows the changed values.

To show you an example (13-6), I take a tutorial:

http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJABIEED

And I change it, including the button and its action:

Button button = new Button("Modify"); button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { String name = table.getItems().get(0).getFirstName(); name = name + "aaaa"; table.getItems().get(0).setFirstName(name); } }); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.getChildren().addAll(label, table, button); vbox.setPadding(new Insets(10, 0, 0, 10)); 

I assume this is a mistake in the presentation of the table, but is there a chance to fix this?

Thank!

+6
javafx-2 tableview
Jun 06 2018-12-06T00:
source share
2 answers

so that TableView can track data changes, you need to set the appropriate fields as JavaFX properties. Add the following methods to the Person class from the tutorial:

  public SimpleStringProperty firstNameProperty() { return firstName; } public SimpleStringProperty lastNameProperty() { return lastName; } public SimpleStringProperty emailProperty() { return email; } 
+21
Jun 06 '12 at 12:37
source share
β€” -

An error appears in the TableView update ( https://javafx-jira.kenai.com/browse/RT-22463 ). I had a similar problem and after some searching this is my workaround. I found that if the columns are deleted and then added again, the table is updated.

 public static <T,U> void refreshTableView(TableView<T> tableView, List<TableColumn<T,U>> columns, List<T> rows) { tableView.getColumns().clear(); tableView.getColumns().addAll(columns); ObservableList<T> list = FXCollections.observableArrayList(rows); tableView.setItems(list); } 


Usage example:

 refreshTableView(myTableView, Arrays.asList(col1, col2, col3), rows); 
+3
Sep 04 '13 at 0:23
source share



All Articles