窗口上的动态x位置调整大小

时间:2015-07-02 10:57:02

标签: layout javafx-8

我有一个按钮。点击该按钮。我正在打开它下面的堆栈窗格。对于StackPane硬编码的x布局值。因此,首先单击按钮下方的堆栈窗口。问题是当我最大化或调整窗口大小时,它没有调整它的位置(x)。

FXML

<Button fx:id="searchCriteriaBtn" mnemonicParsing="false" onAction="#searchCriteriaAction" styleClass="redButton" text="Search Criteria">

<StackPane fx:id="searchCriteriaPane" alignment="TOP_RIGHT" prefHeight="150.0" prefWidth="200.0" styleClass="redBorder" translateX="239.0" translateY="-6.0" visible="false">

JAVA

@FXML
    private void searchCriteriaAction(ActionEvent event){

        searchCriteriaPane.visibleProperty().setValue(true);

        searchCriteriaBtn.layoutXProperty().bind(searchCriteriaPane.layoutXProperty());
        searchCriteriaBtn.layoutYProperty().bind(searchCriteriaPane.layoutYProperty());

    }

1 个答案:

答案 0 :(得分:0)

我找到了叠加下拉菜单的解决方案。

                        <MenuButton mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT"
                            styleClass="redButton" text="Search Criteria" textFill="WHITE">
                            <items>
                                <MenuItem mnemonicParsing="false"
                                    style="-fx-background-color: transparent; -fx-padding: 0; -fx-margin: 0;">

                                        <AnchorPane minHeight="0.0" minWidth="0.0"
                                            prefHeight="500.0" prefWidth="345.0" styleClass="noborder">
                                            <children>

                                                <HBox layoutY="156.0" minHeight="185.0" minWidth="345.0"
                                                    prefHeight="185.0" prefWidth="357.0" />

                                                <HBox layoutX="5.0" layoutY="316.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>


                                            </children>
                                        </AnchorPane>

                                </MenuItem>
                            </items>
                            <HBox.margin>
                                <Insets left="6.0" />
                            </HBox.margin>
                            <cursor>
                                <Cursor fx:constant="HAND" />
                            </cursor>
                        </MenuButton>