I am building a calander/planner application using JavaFX. The app consists of a single GridPane with 35 (7x5) VBox's. Within these VBox's are TaskButtons (implemented below). When I right click a TaskBox it will turn the text to grey and when I left click the TsskButton I want it to delete the button. Things I know already.
- AnchorPaneNode (extends VBox) doesn't have a static getChildren() method.
- I cannot create a separate instance variable for pane since I will not know how many I will have.
- getParent().getChildren() doesn't work because the parents method of getChildren() is not visible.
- VBox has a public getChildren(), but it is not static.
- I tried to make a static accessor to getChildren(), but was unable to.
What else can I try to get this button removed when right clicking? Thank you for your help!
public class TaskButton extends Button {
protected int buttonNum = AnchorPaneNode.listIndex;
public TaskButton(String str)
{
super(str);
setStyle("-fx-background-color: transparent;");
setOnMouseClicked(e -> {
if(e.getButton() == MouseButton.SECONDARY)
{
//I want to remove this button from the VBox, neither of these work
AnchorPaneNode.getChildren().remove(this);
//or
getParent().getChildren().remove(this);
}
else if(e.getButton() == MouseButton.PRIMARY)
{
setStyle("-fx-background-color: transparent; -fx-text-fill: #666666;");
}
});
}
}