简体   繁体   English

如何使辅助锚定板扩展其尺寸以适合主锚定板?

[英]How to make the secondary anchorpane extend its size to fit the main anchorpane?

I do not know how to set secondary Anchorpane from another View to the boundaries of the main View (in fxml code it will be named holderPane and have gray area), so that when the window is expanded, it stretches along with it. 我不知道如何将另一个View中的辅助Anchorpane设置为主View的边界(在fxml代码中,它将命名为holderPane并具有灰色区域),以便在窗口展开时随其一起伸展。 I do everything through SceneBuilder . 我通过SceneBuilder进行所有SceneBuilder

This is after I just maximized my window: 这是在我最大化窗口之后:

我的GettinStart视图,其中包括另一个视图-StoksView

The gray area is just that Anchorpane , to which I try to tie/set another. 灰色区域就是Anchorpane ,我尝试Anchorpane绑定/设置另一个区域。 In the code for the main controller for GettingStart.fxml , I'm writing: GettingStart.fxml主控制器的代码中,我正在写:

@FXML
    private AnchorPane holderPane;

    private void setNode(Node node) {
        holderPane.getChildren().clear();
        holderPane.getChildren().add((Node) node);
    }
    @FXML
    public void initialize() {

        try {

            AnchorPane marketPane = FXMLLoader.load(getClass().getResource("../view/StocksView.fxml"));

            for (Node node:sidePane.getChildrenUnmodifiable()) {
                System.out.println(node.getAccessibleText());
            }

            for (Node node : sidePane.getChildren()) {
                if (node.getAccessibleText() != null) {
                    node.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent ev) -> {
                        switch (node.getAccessibleText()) {
                            case "storesMenu":
                                setNode(marketPane);
                                txtCurrentWindow.setText("Stores");
                                break;

GettingStart.fxml GettingStart.fxml

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

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXToolbar?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView?>
<?import de.jensd.fx.glyphs.octicons.OctIconView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.lexkom.controll.StartwindowController">
   <children>
      <AnchorPane fx:id="sidePane" prefHeight="600.0" prefWidth="210.0" style="-fx-background-color: #363d49;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <Label alignment="BASELINE_LEFT" layoutX="31.0" layoutY="102.0" prefHeight="31.0" prefWidth="136.0" text="Navigation" textFill="WHITE">
               <font>
                  <Font size="14.0" />
               </font>
            </Label>
            <Pane prefHeight="71.0" prefWidth="210.0" style="-fx-background-color: #363d49;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
               <children>
                  <Label layoutX="21.0" layoutY="18.0" prefHeight="31.0" prefWidth="165.0" text="MyDimplomaProject" textFill="WHITE">
                     <font>
                        <Font size="16.0" />
                     </font>
                  </Label>
               </children>
            </Pane>
            <JFXButton fx:id="store" accessibleText="storesMenu" alignment="BASELINE_LEFT" graphicTextGap="17.0" layoutX="15.0" layoutY="152.0" prefHeight="50.0" prefWidth="180.0" ripplerFill="WHITE" text="Stores" textFill="WHITE">
               <font>
                  <Font size="18.0" />
               </font>
               <graphic>
                  <OctIconView fill="WHITE" glyphName="DATABASE" size="17" />
               </graphic>
            </JFXButton>
            <JFXButton fx:id="currency" accessibleText="currancyMenu" alignment="BASELINE_LEFT" graphicTextGap="17.0" layoutX="15.0" layoutY="200.0" prefHeight="50.0" prefWidth="180.0" ripplerFill="WHITE" text="Currancy Rates" textFill="WHITE">
               <font>
                  <Font size="18.0" />
               </font>
               <graphic>
                  <MaterialDesignIconView fill="WHITE" glyphName="CHART_AREASPLINE" size="17" />
               </graphic>
            </JFXButton>
            <Separator layoutX="15.0" layoutY="345.0" prefHeight="0.0" prefWidth="200.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="345.0" />
            <Pane layoutX="15.0" layoutY="365.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0">
               <children>
                  <ImageView fitHeight="50.0" fitWidth="51.0" layoutX="1.0" layoutY="1.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../resources/User_Avatar-64.png" />
                     </image>
                  </ImageView>
                  <Label layoutX="53.0" layoutY="6.0" text="User name" textFill="WHITE">
                     <font>
                        <Font size="16.0" />
                     </font>
                  </Label>
               </children>
            </Pane>
            <JFXButton fx:id="logoutBtn" alignment="BASELINE_LEFT" graphicTextGap="17.0" layoutX="15.0" layoutY="435.0" onAction="#logOut" prefHeight="50.0" prefWidth="180.0" ripplerFill="WHITE" text="Log Out" textFill="WHITE">
               <font>
                  <Font size="18.0" />
               </font>
               <graphic>
                  <FontAwesomeIconView fill="WHITE" glyphName="SIGN_OUT" size="17" />
               </graphic>
            </JFXButton>
            <JFXButton alignment="BASELINE_LEFT" graphicTextGap="17.0" layoutX="15.0" layoutY="485.0" onAction="#closelabel" prefHeight="50.0" prefWidth="180.0" ripplerFill="WHITE" text="Exit" textFill="WHITE">
               <font>
                  <Font size="18.0" />
               </font>
               <graphic>
                  <FontAwesomeIconView fill="WHITE" glyphName="POWER_OFF" size="17" />
               </graphic>
            </JFXButton>
            <Label graphicTextGap="16.0" layoutX="30.0" layoutY="560.0" text="About" textFill="WHITE" />
         </children>
      </AnchorPane>
      <JFXToolbar fx:id="window" layoutX="210.0" prefHeight="48.0" prefWidth="791.0" style="-fx-background-color: #363d49;" AnchorPane.leftAnchor="209.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <center>
            <Label fx:id="txtCurrentWindow" textFill="WHITE" BorderPane.alignment="CENTER">
               <font>
                  <Font name="System Bold" size="22.0" />
               </font>
            </Label>
         </center>
         <right>
            <HBox prefHeight="48.0" prefWidth="129.0" BorderPane.alignment="CENTER">
               <children>
                  <Pane prefHeight="200.0" prefWidth="60.0">
                     <children>
                        <MaterialDesignIconView fill="WHITE" glyphName="WINDOW_MINIMIZE" layoutX="12.0" layoutY="34.0" onMousePressed="#minimizeStage" size="16" />
                     </children>
                  </Pane>
                  <Pane prefHeight="200.0" prefWidth="60.0">
                     <children>
                        <MaterialDesignIconView fill="WHITE" glyphName="WINDOW_MAXIMIZE" layoutX="12.0" layoutY="31.0" onMousePressed="#maximizeStage" size="16" />
                     </children>
                  </Pane>
                  <Pane prefHeight="200.0" prefWidth="60.0">
                     <children>
                        <MaterialDesignIconView fill="WHITE" glyphName="WINDOW_CLOSE" layoutX="9.0" layoutY="31.0" onMouseClicked="#closelabel" onMousePressed="#closelabel" size="16" text="" />
                     </children>
                  </Pane>
               </children>
            </HBox>
         </right>
      </JFXToolbar>
      <AnchorPane fx:id="holderPane" layoutX="215.0" layoutY="54.0" opacity="0.8" prefHeight="540.0" prefWidth="780.0" style="-fx-background-color: #9a9b9d;" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="215.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="54.0" />
   </children>
</AnchorPane>

where StocksView.fxml has the dimensions of the gray area in its normal form. StocksView.fxml的正常形式具有灰色区域的尺寸。

StocksView.fxml StocksView.fxml

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

<?import com.jfoenix.controls.JFXTabPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="540.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <JFXTabPane layoutX="323.0" layoutY="191.0" prefHeight="540.0" prefWidth="780.0" style="-fx-background-color: #fff;" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <tabs>
            <Tab closable="false" text="Manage Sheets">
              <content>
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
              </content>
            </Tab>
            <Tab closable="false" text="Store">
               <content>
                  <fx:include source="TabStockView.fxml" />
               </content></Tab>
         </tabs>
         <effect>
            <DropShadow />
         </effect>
      </JFXTabPane>
   </children>
</AnchorPane>

Simply set the anchors to 0 to make the parent AnchorPane resize the child to fill it's whole area: 只需将锚点设置为0即可使父级AnchorPane调整子AnchorPane大小以填充整个区域:

private void setNode(Node node) {
    AnchorPane.setBottomAnchor(node, 0);
    AnchorPane.setTopAnchor(node, 0);
    AnchorPane.setLeftAnchor(node, 0);
    AnchorPane.setRightAnchor(node, 0);

    holderPane.getChildren().setAll(node);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM