使用屏幕尺寸调整大小

时间:2016-09-16 14:22:29

标签: javafx fxml

如何将AnchorPane绑定到屏幕大小?

当我运行我的代码时,它向我显示:

enter image description here

但是当主舞台适合屏幕时,AnchorPane仍然具有相同的尺寸。

enter image description here

这是我的fxml文件

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

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

<AnchorPane id="AnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sanad.Entry_Page">
   <children>
      <Pane blendMode="RED" layoutX="563.0" layoutY="9.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefHeight="746.0" prefWidth="447.0">
         <padding>
            <Insets top="10.0" />
         </padding>
         <children>
            <SplitPane dividerPositions="0.5720620842572062" layoutX="-56.0" layoutY="-1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="741.0" prefWidth="508.0">
              <items>
                <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="751.0" prefWidth="286.0">
                     <children>
                        <TextField fx:id="formnumer_field" layoutX="8.0" layoutY="14.0" prefHeight="30.0" prefWidth="235.0" />
                        <TextField fx:id="sectornumber_field" layoutX="8.0" layoutY="48.0" prefHeight="30.0" prefWidth="235.0" />
                        <TextField fx:id="fathername_field" layoutX="8.0" layoutY="82.0" prefHeight="30.0" prefWidth="235.0" />
                        <ComboBox fx:id="fatherborn_year" layoutX="8.0" layoutY="116.0" prefHeight="25.0" prefWidth="70.0" />
                        <ComboBox fx:id="fatherborn_month" layoutX="85.0" layoutY="116.0" prefHeight="25.0" prefWidth="70.0" />
                        <ComboBox fx:id="fatherborn_day" layoutX="162.0" layoutY="116.0" prefHeight="25.0" prefWidth="80.0" />
                        <TextField fx:id="fathercurrentjob" layoutX="8.0" layoutY="145.0" prefHeight="30.0" prefWidth="235.0" />
                        <TextField fx:id="fatherprevjob" layoutX="8.0" layoutY="179.0" prefHeight="30.0" prefWidth="235.0" />
                        <TextField fx:id="mothername_field" layoutX="8.0" layoutY="215.0" prefHeight="30.0" prefWidth="235.0" />
                        <TextField fx:id="mother_curr_job" layoutX="8.0" layoutY="278.0" prefHeight="30.0" prefWidth="235.0" />
                        <ComboBox fx:id="motherborn_day" layoutX="162.0" layoutY="249.0" prefHeight="25.0" prefWidth="80.0" />
                        <ComboBox fx:id="motherborn_year" layoutX="8.0" layoutY="249.0" prefHeight="25.0" prefWidth="70.0" />
                        <TextField fx:id="mother_prev_job" layoutX="8.0" layoutY="312.0" prefHeight="30.0" prefWidth="235.0" />
                        <ComboBox fx:id="motherborn_month" layoutX="85.0" layoutY="249.0" prefHeight="25.0" prefWidth="70.0" />
                        <TextField fx:id="homepartner_num" layoutX="8.0" layoutY="346.0" prefHeight="30.0" prefWidth="235.0" />
                        <ComboBox fx:id="homepartner_year" layoutX="11.0" layoutY="382.0" prefHeight="25.0" prefWidth="70.0" />
                        <ComboBox fx:id="homepartner_month" layoutX="88.0" layoutY="382.0" prefHeight="25.0" prefWidth="70.0" />
                        <ComboBox fx:id="homepartner_day" layoutX="163.0" layoutY="382.0" prefHeight="25.0" prefWidth="80.0" />
                        <ComboBox fx:id="homepartner_name" layoutX="8.0" layoutY="416.0" prefHeight="30.0" prefWidth="235.0" />
                        <CheckBox fx:id="homepartner_gender1" layoutX="141.0" layoutY="456.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="100.0" text="ذكر">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </CheckBox>
                        <CheckBox fx:id="homepartner_gender2" layoutX="8.0" layoutY="456.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="100.0" text="أنثى">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </CheckBox>
                        <Label fx:id="current_cityaa" alignment="CENTER" layoutX="141.0" layoutY="490.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="المحافظة">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <TextField fx:id="current_city" layoutX="8.0" layoutY="490.0" prefHeight="30.0" prefWidth="120.0" />
                        <Label fx:id="current_cityaa1" alignment="CENTER" layoutX="141.0" layoutY="530.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="الحي">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <TextField fx:id="current_suberb" layoutX="8.0" layoutY="530.0" prefHeight="30.0" prefWidth="120.0" />
                        <TextField fx:id="prev_suberb" layoutX="11.0" layoutY="615.0" prefHeight="30.0" prefWidth="120.0" />
                        <Label fx:id="current_cityaa11" alignment="CENTER" layoutX="144.0" layoutY="615.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="الحي">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <Label fx:id="current_cityaa2" alignment="CENTER" layoutX="144.0" layoutY="575.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="المحافظة">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <TextField fx:id="prev_city" layoutX="11.0" layoutY="575.0" prefHeight="30.0" prefWidth="120.0" />
                     </children>
                  </AnchorPane>
                <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
                     <children>
                        <Label fx:id="formnumber" contentDisplay="RIGHT" layoutX="8.0" layoutY="14.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="رقم الاستمارة" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <Label fx:id="sectornumber" contentDisplay="RIGHT" layoutX="8.0" layoutY="48.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="رقم القطاع" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="fathername" contentDisplay="RIGHT" layoutX="8.0" layoutY="82.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="اسم الأب" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="fatherborn" contentDisplay="RIGHT" layoutX="20.0" layoutY="112.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="المواليد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="currentjob" contentDisplay="RIGHT" layoutX="20.0" layoutY="142.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل الحالي" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="previousjob" contentDisplay="RIGHT" layoutX="20.0" layoutY="172.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل السابق" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="fatherborn1" contentDisplay="RIGHT" layoutX="20.0" layoutY="244.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="المواليد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="currentjob1" contentDisplay="RIGHT" layoutX="20.0" layoutY="278.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل الحالي" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="fathername1" contentDisplay="RIGHT" layoutX="8.0" layoutY="208.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="اسم الأم" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="previousjob1" contentDisplay="RIGHT" layoutX="20.0" layoutY="307.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل السابق" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="homepartner_sex" contentDisplay="RIGHT" layoutX="20.0" layoutY="451.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الجنس" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="homepartner_name" contentDisplay="RIGHT" layoutX="20.0" layoutY="414.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الاسم" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="partner_born" contentDisplay="RIGHT" layoutX="20.0" layoutY="378.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الميلاد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label fx:id="home_partner" contentDisplay="RIGHT" layoutX="8.0" layoutY="341.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="عدد المستضافين" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                           <font>
                              <Font size="14.0" />
                           </font>
                           <padding>
                              <Insets left="50.0" />
                           </padding>
                        </Label>
                        <Label alignment="CENTER" layoutX="8.0" layoutY="485.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="175.0" text="السكن الحالي">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                        <Label alignment="CENTER" layoutX="8.0" layoutY="570.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="175.0" text="السكن الحالي">
                           <font>
                              <Font size="14.0" />
                           </font>
                        </Label>
                     </children>
                  </AnchorPane>
              </items>
            </SplitPane>
         </children>
      </Pane>
      <SplitPane dividerPositions="0.4845360824742268" layoutX="8.0" layoutY="8.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="741.0" prefWidth="487.0">
        <items>
          <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
          <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="327.0" prefWidth="100.0" />
        </items>
      </SplitPane>
   </children>
</AnchorPane>

2 个答案:

答案 0 :(得分:0)

我尝试用这个fxml做一些事情,但我觉得这很糟糕。你应该重建一切。对于正确的站点,最好使用GridPane而不是AnchorPane并将所有元素放在网格中。 我在这个hobx中创建了HBox,我放了两个AnchorPane,然后每个AnchorPane我放了你的SplitPane。在此之后,您必须将每个SplitPane与AnchorPane的左右边缘连接起来,如下所示:

  <SplitPane AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">

这是这个fxml: 使用SceneBuilder预览它的工作原理。

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<HBox id="AnchorPane" prefHeight="786.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <AnchorPane prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
      <children>
              <SplitPane dividerPositions="0.4845360824742268" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="741.0" prefWidth="487.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                  <items>
                      <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
                      <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="327.0" prefWidth="100.0" />
                  </items>
              </SplitPane>
      </children>
   </AnchorPane>
   <AnchorPane prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
      <children>
                <SplitPane dividerPositions="0.5720620842572062" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="741.0" prefWidth="508.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                    <items>
                        <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT">
                            <children>
                                <TextField fx:id="formnumer_field" layoutX="8.0" layoutY="14.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="43.0" />
                                <TextField fx:id="sectornumber_field" layoutX="8.0" layoutY="48.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="43.0" />
                                <TextField fx:id="fathername_field" layoutX="8.0" layoutY="82.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="43.0" />
                                <ComboBox fx:id="fatherborn_year" layoutX="8.0" layoutY="116.0" prefHeight="25.0" prefWidth="70.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="226.0" />
                                <ComboBox fx:id="fatherborn_month" layoutX="85.0" layoutY="116.0" prefHeight="25.0" prefWidth="70.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="226.0" />
                                <ComboBox fx:id="fatherborn_day" layoutX="162.0" layoutY="116.0" prefHeight="25.0" prefWidth="80.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="226.0" />
                                <TextField fx:id="fathercurrentjob" layoutX="8.0" layoutY="145.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <TextField fx:id="fatherprevjob" layoutX="8.0" layoutY="179.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <TextField fx:id="mothername_field" layoutX="8.0" layoutY="215.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <TextField fx:id="mother_curr_job" layoutX="8.0" layoutY="278.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <ComboBox fx:id="motherborn_day" layoutX="162.0" layoutY="249.0" prefHeight="25.0" prefWidth="80.0" AnchorPane.rightAnchor="73.0" />
                                <ComboBox fx:id="motherborn_year" layoutX="8.0" layoutY="249.0" prefHeight="25.0" prefWidth="70.0" />
                                <TextField fx:id="mother_prev_job" layoutX="8.0" layoutY="312.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <ComboBox fx:id="motherborn_month" layoutX="85.0" layoutY="249.0" nodeOrientation="LEFT_TO_RIGHT" />
                                <TextField fx:id="homepartner_num" layoutX="8.0" layoutY="346.0" prefHeight="30.0" prefWidth="235.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <ComboBox fx:id="homepartner_year" layoutX="11.0" layoutY="382.0" />
                                <ComboBox fx:id="homepartner_month" layoutX="88.0" layoutY="382.0" />
                                <ComboBox fx:id="homepartner_day" layoutX="163.0" layoutY="382.0" />
                                <ComboBox fx:id="homepartner_name" layoutX="8.0" layoutY="416.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="72.0" />
                                <CheckBox fx:id="homepartner_gender1" layoutX="141.0" layoutY="456.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="100.0" text="ذكر">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </CheckBox>
                                <CheckBox fx:id="homepartner_gender2" layoutX="8.0" layoutY="456.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="100.0" text="أنثى">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </CheckBox>
                                <Label fx:id="current_cityaa" alignment="CENTER" layoutX="141.0" layoutY="490.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="المحافظة" AnchorPane.rightAnchor="74.0">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <TextField fx:id="current_city" layoutX="8.0" layoutY="490.0" AnchorPane.leftAnchor="8.0" />
                                <Label fx:id="current_cityaa1" alignment="CENTER" layoutX="141.0" layoutY="530.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="الحي" AnchorPane.rightAnchor="74.0">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <TextField fx:id="current_suberb" layoutX="8.0" layoutY="530.0" AnchorPane.leftAnchor="8.0" />
                                <TextField fx:id="prev_suberb" layoutX="11.0" layoutY="615.0" AnchorPane.leftAnchor="11.0" />
                                <Label fx:id="current_cityaa11" alignment="CENTER" layoutX="144.0" layoutY="615.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="الحي" AnchorPane.rightAnchor="71.0">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <Label fx:id="current_cityaa2" alignment="CENTER" layoutX="144.0" layoutY="575.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="100.0" text="المحافظة" AnchorPane.rightAnchor="71.0">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <TextField fx:id="prev_city" layoutX="11.0" layoutY="575.0" AnchorPane.leftAnchor="11.0" />
                            </children>
                        </AnchorPane>
                        <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
                            <children>
                                <Label fx:id="formnumber" contentDisplay="RIGHT" layoutX="8.0" layoutY="14.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="رقم الاستمارة" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <Label fx:id="sectornumber" contentDisplay="RIGHT" layoutX="8.0" layoutY="48.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="رقم القطاع" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="fathername" contentDisplay="RIGHT" layoutX="8.0" layoutY="82.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="اسم الأب" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="fatherborn" contentDisplay="RIGHT" layoutX="20.0" layoutY="112.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="المواليد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="currentjob" contentDisplay="RIGHT" layoutX="20.0" layoutY="142.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل الحالي" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="previousjob" contentDisplay="RIGHT" layoutX="20.0" layoutY="172.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل السابق" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="fatherborn1" contentDisplay="RIGHT" layoutX="20.0" layoutY="244.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="المواليد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="currentjob1" contentDisplay="RIGHT" layoutX="20.0" layoutY="278.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل الحالي" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="fathername1" contentDisplay="RIGHT" layoutX="8.0" layoutY="208.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="اسم الأم" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="previousjob1" contentDisplay="RIGHT" layoutX="20.0" layoutY="307.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="العمل السابق" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="homepartner_sex" contentDisplay="RIGHT" layoutX="20.0" layoutY="451.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الجنس" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="homepartner_name" contentDisplay="RIGHT" layoutX="20.0" layoutY="414.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الاسم" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="partner_born" contentDisplay="RIGHT" layoutX="20.0" layoutY="378.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="127.0" text="الميلاد" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label fx:id="home_partner" contentDisplay="RIGHT" layoutX="8.0" layoutY="341.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="174.0" text="عدد المستضافين" textAlignment="RIGHT" textOverrun="CENTER_ELLIPSIS">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                    <padding>
                                        <Insets left="50.0" />
                                    </padding>
                                </Label>
                                <Label alignment="CENTER" layoutX="8.0" layoutY="485.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="175.0" text="السكن الحالي">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                                <Label alignment="CENTER" layoutX="8.0" layoutY="570.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="30.0" prefWidth="175.0" text="السكن الحالي">
                                    <font>
                                        <Font size="14.0" />
                                    </font>
                                </Label>
                            </children>
                        </AnchorPane>
                    </items>
                </SplitPane>
              <Pane blendMode="RED" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="-Infinity" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                  <padding>
                      <Insets top="10.0" />
                  </padding>
              </Pane>
      </children>
   </AnchorPane>
</HBox>

答案 1 :(得分:0)

这可以使用AnchorPane的这个属性来完成:

AnchorPane.bottomAnchor
AnchorPane.leftAnchor
AnchorPane.rightAnchor
AnchorPane.topAnchor

但是你需要决定一个场景的哪个部分会改变,哪个部分不会改变。固定部分的宽度用prefWidth固定。给定固定部件的大小,使用AnchorPane.leftAnchor或AnchorPane.rightAnchor进行部件修复。

样品:

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

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

<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sanad.Entry_Page">
   <children>
      <Accordion prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
        <panes>
          <TitledPane animated="false" text="untitled 1">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
            </content>
          </TitledPane>
          <TitledPane animated="false" text="untitled 2">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
            </content>
          </TitledPane>
          <TitledPane animated="false" text="untitled 3">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
            </content>
          </TitledPane>
        </panes>
      </Accordion>
      <SplitPane dividerPositions="0.5" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="200.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <items>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
               <children>
                  <LineChart AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <xAxis>
                      <CategoryAxis side="BOTTOM" />
                    </xAxis>
                    <yAxis>
                      <NumberAxis side="LEFT" />
                    </yAxis>
                  </LineChart>
               </children>
            </AnchorPane>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
               <children>
                  <TableView prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <columns>
                      <TableColumn prefWidth="75.0" text="C1" />
                      <TableColumn prefWidth="75.0" text="C2" />
                    </columns>
                  </TableView>
               </children>
            </AnchorPane>
        </items>
      </SplitPane>
   </children>
</AnchorPane>