php83
php83

Reputation: 101

Add new row at top fxml tableview

I am able to add new row at below the existing row but I want to add new row at top of the existing row.

Is is possible with JavaFX? If yes then could you please guide me how to?

Upvotes: 0

Views: 1720

Answers (1)

ItachiUchiha
ItachiUchiha

Reputation: 36792

Let us say that the TableView has items set to an ObservableList data.

tableView.setItems(data);

When we need to add a new element at the top of the tableview, we add it to the top of the ObservableList. In order to add an element to top of the list we add it at index 0 using the add(index, element) :

data.add(0, newItem);

Upvotes: 2

Related Questions