• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to update table of one fxml by clicking button of other fxml?

 
drashti pandya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have TableView and add button in my first.fxml when i click on add button it should display second.fxml and take input form user.when i click save button in second.fxml Tableview in first.fxml should be update with user input which i take in second.fxml.
first.fxml
@FXML
public void handlePriceSaveButton(ActionEvent a){
Stage stage = new Stage();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("second.fxml"));
Parent root = (Parent) fxmlLoader.load();
FirstController controller=fxmlLoader.<FirstController>getController();
stage.setScene(new Scene(root));
stage.show();
}

second.fxml

@FXML
Button SaveButton;
private ObservableList<Person1> data = FXCollections.observableArrayList();
FXMLLoader fxmlLoader1 = new FXMLLoader(getClass().getResource("Sys1.fxml"));
Sys1Controller controller=fxmlLoader1.<Sys1Controller>getController();


@FXML
public void handleAddOnButtonAction(ActionEvent a){
data.add(new Person1(
ChargeNameText.getText(),
ChargeValue.getText(),
"hi","hello"));
ChargeNameText.clear();
ChargeValue.clear();

Stage stage = (Stage) SaveButton.getScene().getWindow();
stage.close();
}


@Override
public void initialize(URL location, ResourceBundle resources) {
controller.AddOnColumn.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person1,String>("AddOn Name"));
controller.ValueColumn.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person1,String>("Value"));
controller.ByPercentageColumn.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person1,String>("By Percentage"));
controller.TaxColumn.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person1,String>("Tax Exclusive"));
controller.PriceTable.setItems(data);
}

public class Person1 {
private final StringProperty AddOnColumn;
private final StringProperty ValueColumn;
private final StringProperty ByPercentageColumn;
private final StringProperty TaxColumn;
// private final ObjectProperty<LocalDate> birthday;
public Person1() {
this(null, null,null,null);
}
public Person1(String AddOnColumn, String ValueColumn,String ByPercentageColumn,String TaxColumn) {
this.AddOnColumn = new SimpleStringProperty(AddOnColumn);
this.ValueColumn = new SimpleStringProperty(ValueColumn);
this.ByPercentageColumn = new SimpleStringProperty(ByPercentageColumn);
this.TaxColumn = new SimpleStringProperty(TaxColumn);
}
public String getAddOnColumn() {
return AddOnColumn.get();
}
public void setAddOnColumn(String AddOnColumn) {
this.AddOnColumn.set(AddOnColumn);
}
public StringProperty AddOnColumnProperty() {
return AddOnColumn;
}
public String getValueColumn() {
return ValueColumn.get();
}
public void setValueColumn(String ValueColumn) {
this.ValueColumn.set(ValueColumn);
}
public StringProperty ValueColumnProperty() {
return ValueColumn;
}
public String getByPercentageColumn() {
return ByPercentageColumn.get();
}
public void setByPercentageColumn(String ByPercentageColumn) {
this.ByPercentageColumn.set(ByPercentageColumn);
}
public StringProperty ByPercentageColumnProperty() {
return ByPercentageColumn;
}
public String getTaxColumn() {
return TaxColumn.get();
}
public void setTaxColumn(String TaxColumn) {
this.TaxColumn.set(TaxColumn);
}
public StringProperty TaxColumnProperty() {
return TaxColumn;
}
}

}
But it shows error in initialize method in first line null pointer exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic