单击JavaFX VBox中的空白区域

单击JavaFX VBox中的空白区域,javafx,mouseevent,Javafx,Mouseevent,我有一个位于边框窗格(左侧)中的VBox,因此它会自动调整为整个边框窗格的高度。我在此VBox中放置了许多面板,但它们没有占据整个高度,这意味着底部有一些空白。BorderPane依次位于StackPane中,因此在它的“下面”有层 我想要的是,在这个空白区域中单击鼠标可以传递到BorderPane下面的窗格。Web搜索让我相信,正确的方法是使VBox透明,并将其设置为pickonbourds=“false” 我尝试使用style=“-fx背景色:rgba(0,0,0,0);”和opacity=

我有一个位于边框窗格(左侧)中的VBox,因此它会自动调整为整个边框窗格的高度。我在此VBox中放置了许多面板,但它们没有占据整个高度,这意味着底部有一些空白。BorderPane依次位于StackPane中,因此在它的“下面”有层

我想要的是,在这个空白区域中单击鼠标可以传递到BorderPane下面的窗格。Web搜索让我相信,正确的方法是使VBox透明,并将其设置为
pickonbourds=“false”

我尝试使用
style=“-fx背景色:rgba(0,0,0,0);”
opacity=“0”
,使VBox透明,但两者都不能产生所需的效果-似乎即使使用
pickOnBounds=“false”
透明,VBox仍然在其空白区域中使用鼠标事件,并且不允许它们进入StackPane中的下一层

下面的FXML说明了这个问题。两个切换按钮位于StackPane的底层。在左侧,按钮被VBox覆盖,无法单击。在右边,按钮被锚烷覆盖,可以点击

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<StackPane fx:id="stackPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane fx:id="anchorPane">
         <children>
            <ToggleButton mnemonicParsing="false" text="ToggleButton under VBox" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" />
            <ToggleButton mnemonicParsing="false" text="ToggleButton under AnchorPane" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" />
         </children>
      </AnchorPane>
      <BorderPane fx:id="borderPane" pickOnBounds="false" prefHeight="200.0" prefWidth="200.0">
         <left>
            <VBox fx:id="vBox" pickOnBounds="false" prefHeight="200.0" prefWidth="400.0" style="-fx-background-color: rgba(0,0,0,0);" BorderPane.alignment="CENTER">
               <children>
                  <TitledPane animated="false" text="untitled">
                    <content>
                      <AnchorPane fx:id="pane1" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="400.0" />
                    </content>
                  </TitledPane>
                  <TitledPane animated="false" text="untitled">
                    <content>
                      <AnchorPane fx:id="pane2" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="400.0" />
                    </content>
                  </TitledPane>
               </children>
            </VBox>
         </left>
         <center>
            <AnchorPane pickOnBounds="false" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
         </center>
      </BorderPane>
   </children>
</StackPane>

这个问题有解决办法吗?

写下:

-fx-background-color: null;
而不是:

-fx-background-color: rgba(0,0,0,0);

我不知道为什么在这种情况下将背景设置为null和非透明会起作用(因为我希望透明背景也可以正常工作)。

谢谢!现在,如果我能找回我花了三个小时试图弄明白这一点的生活。。。