I need to save column width in user-settings file that i cloud load the TableView with the same width of each column that user previously given for better user experience.
In my research there is a listener on change in width property
tcName.widthProperty().addListener(new ChangeListener<Number>() {});
Where "tcName" is column object.
this is firing several times in a raw while changing the column width.
is there any event called changed ? Or
any possiblility to get output like below
@FXML
private TableView<ItemEmployee> tvData;
@FXML
private TableColumn<ItemEmployee, String> tcCode;
@FXML
private TableColumn<ItemEmployee, String> tcName;
@FXML
private TableColumn<ItemEmployee, String> tcCompany;
tcCode.setCellValueFactory(new PropertyValueFactory<>("Code"));
tcName.setCellValueFactory(new PropertyValueFactory<>("FullName"));
tcCompany.setCellValueFactory(new PropertyValueFactory<>("CompanyName"));
tvData.columnWidthChanged(){
system.out.println("width changed column name: tcCode/Code " );
system.out.println("width of column tcCode/Code : 150" );
saveColumnWidth("tcCode/Code",150);
};
1.Create a boolean variable with default value of false
2.in your
Now handle the close event. there are number of ways to handle the scene close event.e.g. a) Give an Id to your AnchorPane and get the close event like
ap.getScene().getWindow().setOnCloseRequest(event -> { });
b) where you add your stage
primaryStage.setOnCloseRequest(event -> {
c) see this answer
Now in your close event.
{ //Save your ui changes saveColumnWidth("tcCode/Code",150); }
To ease the task of handling multiple columns width. You can do the following
// create a listener
and use it like
Create a common function add call it
public void changelistener(final TableColumn listerColumn) { listerColumn.widthProperty().addListener(new ChangeListener() {
User it like