为什么当我缩小 splitPane 时会出现灰色区域?

Why when I shrink my splitPane a grey area appears?

我的 fxml 界面有问题。 当我尝试减少应用程序的特定部分时,灰色区域覆盖了它。

图片中的例子更能说明问题:

我已经尝试了很多东西(通过修改不同组件的参数),但白色区域仍然存在。

你知道我的问题是什么吗?

代码(示例):

MainApp.java

public class MainApp extends Application {
@Override
public void start(Stage primaryStage) {
    try {
      FXMLLoader loader = new FXMLLoader();

    loader.setLocation(MainApp.class.getResource("view/test.fxml"));
    AnchorPane root = (AnchorPane) loader.load();

    Controller controller = loader.getController();
    controller.setMainApp(this);

    Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    launch(args);
}

Controller.java

public class Controller implements Initializable{

  MainApp mainApp;

  @FXML
  Label label;

  @Override
  public void initialize(URL location, ResourceBundle resources) {
    label.setText("Hello");
  }

  public void setMainApp(MainApp mainApp) {
    this.mainApp = mainApp;
  }
}

test.fxml

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

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane"
    maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
    minHeight="250.0" minWidth="400.0" prefHeight="519.0" prefWidth="921.0"
    xmlns="http://javafx.com/javafx/8.0.111"
    xmlns:fx="http://javafx.com/fxml/1"
    fx:controller="application.view.Controller">
    <children>
        <SplitPane dividerPositions="0.49439102564102566"
            maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
            prefHeight="799.0" prefWidth="1250.0" AnchorPane.bottomAnchor="0.0"
            AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
            AnchorPane.topAnchor="0.0">
            <items>
                <AnchorPane minHeight="400.0" minWidth="400.0"
                    prefHeight="511.0" prefWidth="467.0" rotate="0.0" />
                <AnchorPane minHeight="0.0" minWidth="0.0"
                    prefHeight="797.0" prefWidth="349.0">
                    <children>
                        <SplitPane layoutX="17.0" layoutY="7.0"
                            orientation="VERTICAL" prefHeight="797.0" prefWidth="346.0"
                            AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
                            AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                            <items>
                                <AnchorPane maxHeight="1.7976931348623157E308"
                                    maxWidth="1.7976931348623157E308" minHeight="108.0"
                                    minWidth="447.0" prefHeight="108.0" prefWidth="447.0">
                                    <children>
                                        <SplitPane dividerPositions="0.5248796147672552"
                                            maxHeight="1.7976931348623157E308"
                                            maxWidth="1.7976931348623157E308" minHeight="-Infinity"
                                            minWidth="-Infinity" prefHeight="112.0" prefWidth="442.0"
                                            AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
                                            AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                            <items>
                                                <AnchorPane maxHeight="1.7976931348623157E308"
                                                    maxWidth="1.7976931348623157E308" minHeight="0.0"
                                                    minWidth="0.0" prefHeight="110.0" prefWidth="313.0" />
                                                <AnchorPane maxHeight="1.7976931348623157E308"
                                                    maxWidth="1.7976931348623157E308" minHeight="0.0"
                                                    minWidth="0.0" prefHeight="110.0" prefWidth="87.0">
                                                    <children>
                                                        <Label fx:id="label" layoutX="52.0" layoutY="223.0"
                                                            prefHeight="16.0" prefWidth="96.0" text="Test !">
                                                            <font>
                                                                <Font size="29.0" />
                                                            </font>
                                                        </Label>
                                                    </children>
                                                </AnchorPane>
                                            </items>
                                        </SplitPane>
                                    </children>
                                </AnchorPane>
                            </items>
                        </SplitPane>
                    </children>
                </AnchorPane>
            </items>
        </SplitPane>
    </children>
</AnchorPane>

注意:这个界面是我借助Gluon的SceneBuilder制作的

提前致谢。

SceneBuilder 中,如果我单击根 SplitPane 并将它的分隔线向右滑动,我会得到下面这张图片。这意味着在某些时候,突出显示的 AnchorPane 上的最小值大于其父项的当前宽度。

我基本上把后来的大部分AnchorPanes'首选宽度设置为USE_COMPUTER_SIZE,突出显示的AnchorPane's最小宽度设置为USE_PRE_SIZE,首选宽度设置为USE_COMPUTER_SIZE ].这是我用来解决问题的代码:

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

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="250.0" minWidth="400.0" prefHeight="519.0" prefWidth="921.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.view.Controller">
    <children>
        <SplitPane dividerPositions="0.49836779107725787" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="799.0" prefWidth="1250.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <items>
                <AnchorPane minHeight="400.0" minWidth="400.0" prefHeight="511.0" prefWidth="467.0" rotate="0.0" />
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="797.0" prefWidth="349.0">
                    <children>
                        <SplitPane layoutX="17.0" layoutY="7.0" orientation="VERTICAL" prefHeight="797.0" prefWidth="346.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                            <items>
                                <AnchorPane>
                                    <children>
                                        <SplitPane dividerPositions="0.5248796147672552" minHeight="-Infinity" minWidth="-Infinity" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                            <items>
                                                <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" />
                                                <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="110.0" prefWidth="87.0">
                                                    <children>
                                                        <Label fx:id="label" layoutX="52.0" layoutY="223.0" prefHeight="16.0" prefWidth="96.0" text="Test !">
                                                            <font>
                                                                <Font size="29.0" />
                                                            </font>
                                                        </Label>
                                                    </children>
                                                </AnchorPane>
                                            </items>
                                        </SplitPane>
                                    </children>
                                </AnchorPane>
                            </items>
                        </SplitPane>
                    </children>
                </AnchorPane>
            </items>
        </SplitPane>
    </children>
</AnchorPane>