JAVAFX How to make a button laid out by a shortcut that can be clicked

How to make a button laid out for a shortcut by pressing a button?

Button

Button btn = new Button();
//TODO: button main function, like onPressed, onReleased etc. here...

Custom label

CustomLabel sp = new CustomLabel("Some texts here"));
//TODO: custom label main function, like a translucent background etc here...
//main purpose of this is to overlay the button

Main panel

StackPane mainPane = new StackPane();
mainPane.getChildren.addAll(btn, sp);

At the same time, the area on which the user sticker is applied becomes unattractive.

In any case, so that the button is pressed, even if it is superimposed, for example? Or is there another way to do this? Something like setting a shortcut to invisible when clicked?


EDIT: Answer Itamar Green a question ..

Using an example, as shown in this link: Mouse events are ignored at a basic level , it still does not work. The button laid under the layer is still not available.

sp.setPickOnBounds(false);
+4
2

mouseTransparent (), , true. , node :

@Override
public void start(Stage primaryStage) {
    Button btn = new Button("Say 'Hello World'");
    btn.setOnAction((ActionEvent event) -> {
        System.out.println("Hello World!");
    });
    Region region = new Region();
    region.setStyle("-fx-background-color: #0000ff88;");
    region.setMouseTransparent(true);

    StackPane root = new StackPane(btn, region);

    Scene scene = new Scene(root, 100, 100);

    primaryStage.setScene(scene);
    primaryStage.show();
}

region.setMouseTransparent(true);

- ...

+2

. , .

, , clickable .

Label sp = new Label("some texts here")
sp.setOnMouseClicked(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent e) {
                      //copy over the button event.
                  }
                });

, ...

0

Source: https://habr.com/ru/post/1665071/


All Articles