我不知道如何将辅助Anchorpane
从另一个View
设置为主View
的边界(在fxml代码中,它将命名为holderPane
并且具有灰色区域),以便当窗口展开时,它会随之拉伸。我通过SceneBuilder
完成所有事情。
这是在我最大化窗口之后:
灰色区域只是Anchorpane
,我试图绑定/设置另一个。在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
<?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>
其中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>
答案 0 :(得分:3)
只需将锚点设置为0
即可让父级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);
}