Reputation: 27
I have a button in the java fx which is present in HBox of the UI and I want to delete that Button on clicking the same button.i have written the action event for the same:
@FXML
private HBOx projectlist;
String buttonid;
String buttoname; /** * Initializes the controller class. */ @FXML public Button delete;
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
projectlist.getChildren().remove(buttoname);
}
});
Actually the problem is I am getting the button from other controller in this function and i am not able to use that button in another button(Delete) action event although i am able to use buttonid variable in delete action event: public void setButton(Button button,String buttonname) {
projectlist.setSpacing(10);
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
}
});
projectlist.getChildren().add(button);
} @FXML
private void gotoDelete(ActionEvent event) throws IOException{
ProjectModule.DeleteProject(Integer.parseInt(buttonid));
projectlist.getChildren().remove(button);
}
Upvotes: 0
Views: 5528
Reputation: 209225
Try
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
projectList.getChildren().remove(button);
}
});
Upvotes: 2