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
.
ThenobsList.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
How to Create Sparksession with Hive Support (Fails with "Hive Classes Are Not Found")
Java Streams: Replacing Groupingby and Reducing by Tomap
Convert from List<Completablefuture> to Completablefuture<List>
Resizing Icon to Fit on Jbutton in Java
Problem with "Scopes" of Variables in Try Catch Blocks in Java
Highlighting Strings in Javafx Textarea
Jersey 415 Unsupported Media Type
Providing Input/Subcommands to Command Executed Over Ssh with Jsch
Jtable Model Listener Detects Inserted Rows Too Soon (Before They Are Drawn)
Selenium Switch Focus to Tab, Which Opened After Clicking Link
Differencebetween @Inject and @Autowired in Spring Framework? Which One to Use Under What Condition
Run a Single Test Method with Maven
How to Check If My String Is Equal to Null
How to Read JSON File into Java with Simple JSON Library
When to Close Connection, Statement, Preparedstatement and Resultset in Jdbc
Custom JSON Deserializer Using Gson