アイコンを含むノードにOnMousePressedイベントハンドラを追加し、実行するメソッドをハンドラに追加します。
タスクバーの例!
public static HBox createButtons(String id, int amount, int width, int height) {
Rectangle[] button = new Rectangle[3];
DropShadow glow = new DropShadow();
HBox buttonBox = new HBox(10);
glow.setSpread(.6);
glow.setRadius(10);
buttonBox.getStylesheets().add(Styles.styledToolBarCss);
buttonBox.setId(id);
buttonBox.setAlignment(Pos.TOP_RIGHT);
button[0] = new Rectangle();
button[0].setFill(new ImagePattern(ImagesAndIcons.minimize));
button[0].setWidth(width);
button[0].setHeight(height);
button[0].setOnMouseEntered(e ->{
glow.setColor(Color.DODGERBLUE);
button[0].setEffect(glow);
});
button[0].setOnMouseExited(e ->{
button[0].setEffect(null);
});
button[0].setOnMouseReleased(e ->{
TileMapEditor.minimize();
});
button[1] = new Rectangle();
button[1].setFill(new ImagePattern(ImagesAndIcons.maximize));
button[1].setWidth(width);
button[1].setHeight(height);
button[1].setOnMouseEntered(e ->{
glow.setColor(Color.DODGERBLUE);
button[1].setEffect(glow);
});
button[1].setOnMouseExited(e ->{
button[1].setEffect(null);
});
button[1].setOnMouseReleased(e ->{
TileMapEditor.maximize();
});
button[2] = new Rectangle();
button[2].setFill(new ImagePattern(ImagesAndIcons.exit));
button[2].setWidth(width*1.5);
button[2].setHeight(height);
button[2].setOnMouseEntered(e ->{
glow.setColor(Color.RED);
button[2].setEffect(glow);
});
button[2].setOnMouseExited(e ->{
button[2].setEffect(null);
});
button[2].setOnMouseReleased(e ->{
TileMapEditor.exit();
});
buttonBox.getChildren().setAll(button);
return buttonBox;
}