I am finding hard to clear the table contents in my table. I have tried this code.
for ( int i = 0; i<resultTable.getItems().size(); i++) {
resultTable.getItems().clear();
}
To clarify my question, the problem I am having is that i want to delete the values in my table. This was the first code i used;
public void removeRow(){
allFiles = table.getItems(); fileSelected = table.getSelectionModel().getSelectedItems();
fileSelected.forEach(allFiles :: remove);
}
But it only removes a particular selected row. I want to clear all the rows and leave the table empty at once, without having to select any row. I tried to use this code;
public void removeAllRows(){
for ( int i = 0; i<resultTable.getItems().size(); i++) {
resultTable.getItems().clear();
}
}
but it does not clear all the rows in the table
My plan is to use this method as an action for a button. e.g
Button btn = new ("Clear Table");
btn..setOnAction(e->{removeAllRows();});
When this button is clicked, it should delete all rows in the table at once.
tableView. getItems(). clear() clears all TableView data. No need to loop it.
TableView is a component that is used to create a table populate it, and remove items from it. You can create a table view by instantiating thejavafx. scene. control.
To select a row with a specific index you can use the select(int) method. Here is an example of selecting a single row with a given index in a JavaFX TableView: selectionModel. select(1);
tableView.getItems().clear()
Will do the trick
Try using the following: Name "tableView" to whatever your FXMLtable
is called
for ( int i = 0; i<tableView.getItems().size(); i++) {
tableView.getItems().clear();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With