Combobox使容器/ Combobox中的mouseExit呈现在容器外部

时间:2015-06-30 12:24:18

标签: javafx-8

我的搜索栏是Titlepane。默认情况下会展开(false)。当我将鼠标悬停时,它将展开(true)。当我从该容器中鼠标退出时,它将再次展开(false)。

如果我扩展了Titlepane并尝试从comboBox中选择值,它将自动触发onMouseExited方法。

如何摆脱它。

我的代码:

<TitledPane fx:id="searchCriteria" animated="true" minWidth="-Infinity"  onMouseEntered="#mouseEnter" onMouseExited="#mouseExit" prefHeight="790.0" prefWidth="366.0" style="-fx-font-weight: bold; -fx-border-color: transparent;" text="Search Criteria" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="64.0">
                    <content>
                        <AnchorPane maxWidth="-Infinity" minWidth="-Infinity" prefHeight="730.0" prefWidth="356.0">
                            <children>

                                            <TitledPane animated="true" minWidth="-Infinity" style="-fx-font-weight: bold;" styleClass="hiddenHeader" text="Search Criteria" translateX="-20.0">
                                    <font>
                                        <Font name="Calibri Bold" size="11.0" />
                                    </font>
                                </TitledPane>
                                <VBox prefHeight="706.0" prefWidth="359.0" style="-fx-font-weight: bold;">
                                    <children>
                                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="615.0" prefWidth="200.0" styleClass="noborder">
                                            <children>
                                                <HBox layoutX="10.0" prefHeight="35.0" prefWidth="339.0" spacing="8.0" style="-fx-border-color: transparent;">
                                                    <children>
                                                        <Label prefHeight="14.0" prefWidth="94.0" text="Value Date From">
                                                            <HBox.margin>
                                                                <Insets right="2.0" top="5.0" />
                                                            </HBox.margin>
                                                        </Label>
                                                        <DatePicker prefWidth="100.0" onMouseEntered="#mouseEnter" />
                                                        <Label prefHeight="14.0" prefWidth="20.0" text="  To">
                                                            <HBox.margin>
                                                                <Insets top="5.0" />
                                                            </HBox.margin>
                                                        </Label>
                                                        <DatePicker prefWidth="100.0" onMouseEntered="#mouseEnter" />
                                                    </children>
                                                    <padding>
                                                        <Insets top="10.0" />
                                                    </padding>
                                                    <styleClass>
                                                        <String fx:value="vbox-column" />
                                                        <String fx:value="noborder" />
                                                    </styleClass>
                                                </HBox>

                                                            <HBox layoutY="156.0" minHeight="185.0" minWidth="345.0" prefHeight="185.0" prefWidth="357.0">
                                                    <children>
                                                        <ScrollPane hbarPolicy="NEVER" maxHeight="230.0" minWidth="355.0" prefHeight="216.0" prefWidth="355.0" vbarPolicy="AS_NEEDED">
                                                            <content>
                                                                <VBox fx:id="userSelectedValues" fillWidth="true" layoutY="5.0" maxWidth="355.0">
                                                                </VBox>
                                                            </content>
                                                        </ScrollPane>
                                                    </children>
                                                </HBox>

                                                            <HBox layoutX="7.0" layoutY="350.0" prefHeight="35.0" prefWidth="348.0">
                                                    <children>
                                                        <Text layoutX="7.0" layoutY="335.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Template Name">
                                                            <HBox.margin>
                                                                <Insets right="5.0" top="9.0" />
                                                            </HBox.margin>
                                                        </Text>
                                                        <ComboBox fx:id="templateNameComboBox" layoutX="94.0" layoutY="330.0" prefWidth="248.0" promptText="Select Template Name">
                                                            <HBox.margin>
                                                                <Insets left="7.0" />
                                                            </HBox.margin>
                                                        </ComboBox>
                                                    </children>
                                                </HBox>

                                                            <HBox layoutX="7.0" layoutY="385.0" prefHeight="35.0" prefWidth="348.0">
                                                    <children>
                                                        <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Type of template">
                                                            <HBox.margin>
                                                                <Insets top="9.0" />
                                                            </HBox.margin>
                                                        </Text>
                                                        <ComboBox fx:id="templateTypeComboBox" prefWidth="248.0" promptText="Select Template Type">
                                                            <items>
                                                                <FXCollections fx:factory="observableArrayList">
                                                                    <String fx:value="Private" />
                                                                    <String fx:value="Public" />
                                                                </FXCollections>
                                                            </items>
                                                            <HBox.margin>
                                                                <Insets left="5.0" />
                                                            </HBox.margin>
                                                        </ComboBox>
                                                    </children>
                                                </HBox>
                                                <HBox alignment="TOP_CENTER" layoutX="-8.0" layoutY="422.0" prefHeight="100.0" prefWidth="360.0">
                                                    <children>
                                                        <CheckBox fx:id="defaultTemplate" mnemonicParsing="false" />
                                                        <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Set as a default template">
                                                            <HBox.margin>
                                                                <Insets top="3.0" />
                                                            </HBox.margin>
                                                        </Text>
                                                    </children>
                                                </HBox>
                                                <HBox layoutX="5.0" layoutY="450.0" prefHeight="45.0" prefWidth="352.0">
                                                    <children>
                                                        <Button mnemonicParsing="false" onAction="#onSaveTemplate" prefHeight="45.0" prefWidth="67.0" styleClass="advancedRedButton" text="Save Template" textAlignment="CENTER" wrapText="true" />
                                                        <Button mnemonicParsing="false" onAction="#onEditTemplate" prefHeight="45.0" prefWidth="67.0" styleClass="advancedRedButton" text="Edit Template" textAlignment="CENTER" wrapText="true">
                                                            <HBox.margin>
                                                                <Insets left="8.0" />
                                                            </HBox.margin>
                                                        </Button>
                                                        <Button mnemonicParsing="false" onAction="#onDeleteTemplate" prefHeight="45.0" prefWidth="67.0" styleClass="advancedRedButton" text="Delete Template" textAlignment="CENTER" wrapText="true">
                                                            <HBox.margin>
                                                                <Insets left="8.0" />
                                                            </HBox.margin>
                                                        </Button>
                                                        <Button mnemonicParsing="false" onAction="#onClearTemplate" prefHeight="45.0" prefWidth="55.0" styleClass="advancedRedButton" text="Clear" textAlignment="CENTER" wrapText="true">
                                                            <HBox.margin>
                                                                <Insets left="8.0" />
                                                            </HBox.margin>
                                                        </Button>
                                                        <Button mnemonicParsing="false" onAction="#advancedSearch" prefHeight="45.0" prefWidth="55.0" styleClass="advancedRedButton" text="Search">
                                                            <HBox.margin>
                                                                <Insets left="8.0" />
                                                            </HBox.margin>
                                                        </Button>
                                                    </children>
                                                </HBox>
                                                <HBox layoutX="5.0" layoutY="83.0" prefHeight="73.0" prefWidth="348.0">
                                                    <children>

                                                                    <GridPane fx:id="gridPane" hgap="3.0" layoutX="6.6" layoutY="60.6" prefHeight="43.0" prefWidth="348.0" vgap="1.0" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="-3.0" AnchorPane.rightAnchor="-10.0" AnchorPane.topAnchor="51.0">
                                                            <columnConstraints>
                                                                <ColumnConstraints hgrow="SOMETIMES" maxWidth="132.99999237060547" minWidth="10.0" prefWidth="126.0" />
                                                                <ColumnConstraints hgrow="SOMETIMES" maxWidth="102.0" minWidth="10.0" prefWidth="102.0" />
                                                                <ColumnConstraints hgrow="SOMETIMES" maxWidth="115.0" minWidth="10.0" prefWidth="86.0" />
                                                                <ColumnConstraints hgrow="SOMETIMES" maxWidth="76.0" minWidth="10.0" prefWidth="28.0" />
                                                                <ColumnConstraints />
                                                            </columnConstraints>
                                                            <rowConstraints>
                                                                <RowConstraints maxHeight="140.0" minHeight="10.0" prefHeight="24.0" vgrow="SOMETIMES" />
                                                                <RowConstraints maxHeight="275.0" minHeight="10.0" prefHeight="48.0" vgrow="SOMETIMES" />
                                                            </rowConstraints>
                                                            <children>
                                                                <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Field" textAlignment="CENTER" wrappingWidth="35.9765625" GridPane.halignment="CENTER" GridPane.valignment="CENTER">

                                                                                <styleClass>
                                                                        <String fx:value="boldFont" />
                                                                        <String fx:value="px16Font" />
                                                                    </styleClass>
                                                                </Text>
                                                                <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Operator" GridPane.columnIndex="1" GridPane.halignment="CENTER">

                                                                                <styleClass>
                                                                        <String fx:value="boldFont" />
                                                                        <String fx:value="px16Font" />
                                                                    </styleClass>
                                                                </Text>
                                                                <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Value" GridPane.columnIndex="2" GridPane.halignment="CENTER">

                                                                                <styleClass>
                                                                        <String fx:value="boldFont" />
                                                                        <String fx:value="px16Font" />
                                                                    </styleClass>
                                                                </Text>
                                                                <ComboBox fx:id="fieldName" prefWidth="150.0" promptText="Select Field" GridPane.rowIndex="1">
                                                                    <items>
                                                                        <FXCollections fx:factory="observableArrayList">
                                                                            <String fx:value="BRANCH" />
                                                                            <String fx:value="CURRENTSTATUS" />
                                                                            <String fx:value="INOUTIND" />
                                                                            <String fx:value="DEALNO" />
                                                                            <String fx:value="ORIGINATORREFERENCE" />
                                                                            <String fx:value="RELATEDREFERENCE" />
                                                                            <String fx:value="MESSAGETYPE" />
                                                                            <String fx:value="COUNTERPARTYBIC" />
                                                                            <String fx:value="BUYCCY" />
                                                                            <String fx:value="SELLCCY" />
                                                                            <String fx:value="VALUEDATE" />
                                                                            <String fx:value="UPDATETIME" />
                                                                            <String fx:value="CLSBREFERENCE" />
                                                                            <String fx:value="CLSMATCHINGREFERENCE" />
                                                                            <String fx:value="DEALDATE" />
                                                                            <!-- <String fx:value="Time Difference" /> -->
                                                                        </FXCollections>
                                                                    </items>
                                                                </ComboBox>
                                                                <ComboBox fx:id="operator" prefWidth="150.0" promptText="Select Operator" GridPane.columnIndex="1" GridPane.rowIndex="1">
                                                                    <items>
                                                                        <FXCollections fx:factory="observableArrayList">
                                                                            <String fx:value="IN" />
                                                                            <String fx:value="NOT IN" />
                                                                            <String fx:value="EQUALS" />
                                                                            <String fx:value="NOT EQUALS" />
                                                                            <String fx:value="LESS THAN" />
                                                                            <String fx:value="LESS THAN EQUALS" />
                                                                            <String fx:value="GREATER THAN" />
                                                                            <String fx:value="GREATER THAN EQUALS" />
                                                                        </FXCollections>
                                                                    </items>
                                                                </ComboBox>
                                                                <TextField fx:id="fieldValue" GridPane.columnIndex="2" GridPane.rowIndex="1" />
                                                                <Button mnemonicParsing="false" onAction="#addOptions" prefHeight="20.0" prefWidth="20.0" styleClass="addImg" GridPane.columnIndex="3" GridPane.rowIndex="1">
                                                                    <GridPane.margin>
                                                                        <Insets left="5.0" />
                                                                    </GridPane.margin>
                                                                </Button>
                                                            </children>
                                                        </GridPane>

                                                                </children>
                                                </HBox>
                                                <HBox layoutX="9.0" layoutY="35.0" prefHeight="35.0" prefWidth="345.0" spacing="8.0" styleClass="vbox-column">
                                                    <children>
                                                        <Label prefHeight="14.0" prefWidth="91.0" text="Deal Number">
                                                            <HBox.margin>
                                                                <Insets right="2.0" top="5.0" />
                                                            </HBox.margin>
                                                            <padding>
                                                                <Insets left="2.0" />
                                                            </padding>
                                                        </Label>
                                                        <TextField fx:id="dealNumber" prefWidth="180.0" translateX="-1.0">
                                                            <HBox.margin>
                                                                <Insets left="5.0" />
                                                            </HBox.margin>
                                                        </TextField>
                                                    </children>
                                                    <padding>
                                                        <Insets top="10.0" />
                                                    </padding>
                                                </HBox>
                                            </children>
                                        </AnchorPane>
                                    </children>
                                </VBox>

                                        </children>
                        </AnchorPane>
                    </content>
                    <graphic>
                        <Label layoutX="-20.0" styleClass="triggerLink" text="Search Criteria">
                            <padding>
                                <Insets left="-3.0" right="-17.0" />
                            </padding>
                        </Label>
                    </graphic>
                    <styleClass>
                        <String fx:value="arrowPane" />
                        <String fx:value="greyBorder" />
                    </styleClass>
                    <padding>
                        <Insets right="5.0" />
                    </padding>
                </TitledPane>

控制器

@FXML
private void mouseEnter(){
    searchCriteria.setExpanded(true);       
}

@FXML
private void mouseExit(){
    searchCriteria.setExpanded(false);      
}

1 个答案:

答案 0 :(得分:0)

您应该使用事件过滤器而不是事件处理程序(更多信息:https://docs.oracle.com/javafx/2/events/processing.htm)。 遗憾的是,您无法直接在FXML中定义事件过滤器。您需要使用@FXML在控制器中注入组件,然后在initialize()方法中手动添加事件过滤器。