/************************************************** * Author: Morrison * Date: 13 Apr 2021 **************************************************/ import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.FlowPane; import javafx.scene.input.MouseButton; public class Remove extends Application { FlowPane fp; public Remove() { fp = new FlowPane(); } @Override public void init() { } @Override public void start(Stage primary) { primary.setScene(new Scene(fp, 500, 500)); DieButton b = new DieButton("Click me!"); fp.getChildren().add(b); primary.show(); } @Override public void stop() { } /********************** Inner Classes ***************/ class DieButton extends Button { public DieButton(String s) { super(s); setOnMouseClicked( e -> { if(e.getButton() == MouseButton.SECONDARY || e.isControlDown()) { fp.getChildren().remove(this); } }); } } }