Change background color of items in a left, vertical, icon based menu

PHOTO EMBED

Sun Nov 21 2021 10:52:15 GMT+0000 (Coordinated Universal Time)

Saved by @friedmacher #java #javafx

private TilePane selectedTilePane;
private TilePane currentTilePane;
private ImageView selectedImageView;

void onMouseClicked(MouseEvent event) {
  this.resetTileBackgroundColor();
  this.selectedImageView = (ImageView) event.getSource();
  this.selectedTilePane = (TilePane) this.selectedImageView.getParent();
  this.selectedTilePane.setStyle("-fx-background-color:gray");

}

void onMouseEntered(MouseEvent event) {
  this.currentTilePane = (TilePane) event.getSource();
  if (!this.currentTilePane.equals(this.selectedTilePane)) {
    this.currentTilePane.setStyle("-fx-background-color:lightgray");
  }
}

void onMouseExited(MouseEvent event) {
  this.currentTilePane = (TilePane) event.getSource();
  if (!this.currentTilePane.equals(this.selectedTilePane)) {
    this.currentTilePane.setStyle("-fx-background-color:whitesmoke");
  }
}

private void resetTileBackgroundColor() {
  tilePane<XXXXX>.setStyle("-fx-background-color:whitesmoke");
}
content_copyCOPY

We have a menu based on icons which background shall change depending on if the mouse is hovered over the item or if it is clicked. Assumptions: The Image View is embedded in a Tile Pane. The onMouseClick event is bound to the Image View. The onMouseEntered and onMouseExited event are bound to the TilePane.