Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX 2.1 TableView refresh items

I have this common issue, as it appears to be. My table view wont refresh my items after I reset them. I have checked the data and it's the new one.

I tried multiple solution from internet but no success.

Can't reset all the columns because it adds one empty one extra (dont know why) and the resize just breakes.

My table is not editable. The new data is changed.

The data is refreshed if I change the ordering of the items and the rows change (:|).

I'm just left without ideas.

At the moment the refresh code is pretty simple.

ObservableList<User> data = FXCollections.observableArrayList(User.getResellers()); reseller_table.setItems(data); 

Again the new data is correct. When I make an selection to the tableView it returns the new correct Item.

like image 733
user1236048 Avatar asked Jun 16 '12 16:06

user1236048


People also ask

How to refresh a TableView JavaFX?

Since JavaFX 8u60 you can use(assuming tableView is an instance of TableView class): tableView. refresh();

How do you refresh a scene in JavaFX?

The JavaFX scene can be forcibly refreshed by changing the width or height of the Scene by a fractional number of pixels (for example, 0.001). This change forces the background windowing and rendering services to recalculate layout and rendering requirements for the scene graph.

What is TableView in JavaFX?

The TableView class provides built-in capabilities to sort data in columns. Users can alter the order of data by clicking column headers. The first click enables the ascending sorting order, the second click enables descending sorting order, and the third click disables sorting. By default, no sorting is applied.


2 Answers

Workaround:

 tableView.getColumns().get(0).setVisible(false);  tableView.getColumns().get(0).setVisible(true); 
like image 119
Daniel De León Avatar answered Sep 21 '22 02:09

Daniel De León


Since JavaFX 8u60 you can use(assuming tableView is an instance of TableView class):

tableView.refresh(); 

From the documentation:

Calling refresh() forces the TableView control to recreate and repopulate the cells necessary to populate the visual bounds of the control. In other words, this forces the TableView to update what it is showing to the user. This is useful in cases where the underlying data source has changed in a way that is not observed by the TableView itself.

like image 25
Elltz Avatar answered Sep 19 '22 02:09

Elltz