Javafx 2.1 Tableview Refresh Items

JavaFX 2.1 TableView refresh items

I had a similar problem with refreshing. My solution was to restrict the operations on the ObservableList to those which work correctly with bind().

Assume ObservableList obsList is the underlying list for the TableView.

Then

obsList.clear() (inherited from java.util.List<>) will not update the TableView correctly but.

Also calling setItem(obsList) did not work to trigger a refresh...but...

obsList.removeAll(obsList) (overwritten by ObservableList) works fine because it fires the changeEvent correctly.

Refilling a list with completely new content then works as follows:

  • obsList.removeAll(obsList);
  • obsList.add(...); //e.g. in a loop...

or

  • obsList.removeAll(obsList);
  • FXCollections.copy(obsList, someSourceList)

JavaFx Tableview refresh() method alternative

I was able to fix the issue by using the body of refresh() method. I was unable to use refresh() method in prior versions to mentioned version as the method was private. So I used the body of refresh() instead of refresh().

table.getProperties().put(TableViewSkinBase.RECREATE, Boolean.TRUE);

How to refresh database tableview after updating or Deleting In Javafx?

You can add this to the DialogBoxController class:

public class DialogBoxController {
private Controller controller;
public void setController(Controller controller){
this.controller = controller;
}
@FXML
public void delete(ActionEvent event){

// Your code
controller.refreshTable();
closeStage(event);

}}

And in the Controller:

DialogBoxController dialog = loader.getController();
dialog.editTask(selectedTask);
dialog.setController(this);

How to refresh a TableView in window A from a Window B in javaFX? (Edit)

Pass the table's item list to the second controller:

@FXML
private void openInscriptionWindow(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/inscriptionui/FxmlInscription.fxml"));
Parent root = loader.load();

FxmlInscriptionController controller = loader.getController();
controller.setTableItems(dataTable.getItems());

Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.show();
}

and then simply add the new item to the list:

public class FxmlInscriptionController implements Initializable {

@FXML
private TextField firsNametInput; //first name TextField

@FXML
private TextField lastNameInput; //last name TextField

private ObservableList<DataArray> tableItems ;

public void setTableItems(ObservableList<DataArray> tableItems) {
this.tableItems = tableItems ;
}

@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}

//Show the inserted first name and last name in my TableView in the main window
@FXML
private void saveData(MouseEvent event) throws IOException {

tableItems.add(new DataArray(firsNametInput.getText(), lastNameInput.getText()));

}

}


Related Topics



Leave a reply



Submit