-1

Hello I am an javaFx Developer and I am working on an Desktop Application I am stuck in problem in which I have to clear and update the TableView from an another Controller I Try to call the clearTable() function which is in an another controller but it is not remove all data from tableview So How I can clear all row from table

First Controller

// Add Product Data To Table View From Database    
public void addProductDatabaseFromTableView() {

    try {
        //addProductTable.setItems(data);
        ResultSet resultSet = addNewProductModelObject.getAllProduct();
        while (resultSet.next()) {

            AddProduct addProduct = new AddProduct(resultSet.getString("Product_Code"), resultSet.getString("Product_Name"), resultSet.getInt("Quanlity"), resultSet.getString("Manufactured_date"), resultSet.getString("Expired_date"));
            data.add(addProduct);
        }
    } catch (SQLException ex) {
        Logger.getLogger(AddNewProductController.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(data);
}

Second Controller

public void UpdateProductAction( ActionEvent actionEvent ){
    //System.out.println("UpdateProductAction");
    productModelObject.setProductName(ProductName.getText());
    productModelObject.setProductCode(getProductCode());
    productModelObject.setPrice(Integer.parseInt(RetailPrice.getText()));
    productModelObject.setQuanlity(Integer.parseInt(Quanlity.getText()));
    productModelObject.setManufactureDate(ManuDate.getValue().toString());
    productModelObject.setExpiredDate(ExpDate.getValue().toString());

    boolean checkUpdate = productModelObject.updateProductData();

    if ( checkUpdate ) {
        //System.out.println(checkUpdate);

        //addNewProductController.ClearTableData();
        addNewProductController.addProductDatabaseFromTableView();
        Stage stage = (Stage) BtnClose.getScene().getWindow();
        stage.close();
    }
}

Please Help

1 Answers1

0

You can use an ObservableList and use the method setItems(listName);

Then simple clear all the items from the observable and the changes will be reflected on the Table.

  • How i do this?

Here is a full tutorial

Also this tutorial is a very good start for the next wuestion.

  • How to access a controller from another controller?

Use ´MVP´ or ´MVC´ pattern and add instances from one ´Controller´ to another ´Controller´.

GOXR3PLUS
  • 6,877
  • 9
  • 44
  • 93