0

I am trying to create a pane containing a label and having various buttons on its border. I am new to JavaFx and I do not know if the way I used is the best, however I doubt it since I encounter a problem where the buttons are not clickable in the inner part of the pane, but only in the outer part...

Result

<StackPane>
    <StackPane styleClass="name-box">
        <Label text="Margherita"/>
        <padding>
            <Insets bottom="20.0" left="80.0" right="80.0" top="20.0" />
        </padding>
    </StackPane>
    <HBox alignment="TOP_CENTER" spacing="20.0">
        <Button fx:id="bonus1" styleClass="bonus-button"/>
        <Button fx:id="bonus2" styleClass="bonus-button"/>
        <Button fx:id="bonus3" styleClass="bonus-button"/>
        <Button fx:id="bonus4" styleClass="bonus-button"/>
    <StackPane.margin>
       <Insets top="-12.0" />
    </StackPane.margin>
    </HBox>
    <HBox alignment="BOTTOM_CENTER" spacing="40.0">
        <Button/>
        <Button/>
    <StackPane.margin>
       <Insets bottom="-12.0" />
    </StackPane.margin>
    </HBox>
</StackPane>
.name-box {
    -fx-border-color: #00FFFF;
    -fx-border-width: 2px;
    -fx-effect: dropshadow(gaussian, #00FFFF, 15, 0.3, 0, 0);
}

.bonus-button {
    -fx-background-color: linear-gradient(from 100% 0% to 0% 100%, #5ff7c2, #26CB95);
    -fx-background-radius: 10;
    -fx-cursor: hand;
}

I tried with pickOnBounds="false" and mouseTransparent="true" on the StackPane but nothing... Any advice?

4
  • 3
    Hello Vincenzo Bova, the problem is that your internal panel is on top of the buttons, reverse the order in which you add the buttons and the internal panel to the external panel, and voileau!!!. Commented May 5 at 21:38
  • 2
    The example examined here illustrates a similar problem. Commented May 5 at 21:45
  • 1
    Also see Z-Order in JavaFX Commented May 5 at 23:56
  • 1
    What @MarcePuente said is the way to go. But if for some reason you need to keep the order of the panels as they are, it is possible to put "mouse transparent" to "true" for the inner panel, this way the click will "pass through" the inner panel and land on the next object behind which is the button Commented May 6 at 9:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.