enter image description here

When you click on label1 (yellow), label2, label3 (pink) appear. How to make JavaFX so that when you click on any area of ​​the program window (gray) label2 and label3 disappear?

    1 answer 1

    I can assume that gray is some kind of Pane . So you can hang up the handler on this pane and hide the 2 and 3 laybla

     pane.addEventHandler(MouseEvent.MOUSE_CLICKED, event - > { label2.setVisible(false); label3.setVisible(false); }); 
    • one
      root.setOnMouseClicked ((MouseEvent e) -> {...}); - DimXenon 1:56 pm
    • and root - what is it? - Andrew Bystrov
    • root is usually the root element passed to the scene constructor. For example, Scene scene = new Scene(root, 1200, 900); where root can be VBox, Group or some other Node. - DimXenon