Javafx 为什么缩小拆分窗格时会出现灰色区域?

Javafx 为什么缩小拆分窗格时会出现灰色区域?,javafx,fxml,splitpane,Javafx,Fxml,Splitpane,我的fxml接口有问题。 当我试图减少应用程序的某个特定部分时,会出现一个灰色区域 图中的一个例子更确切地说是: 我尝试了很多方法(通过修改不同组件的参数),但白色区域仍然存在 你知道我的问题是什么吗 代码(示例): MainApp.java public class MainApp extends Application { @Override public void start(Stage primaryStage) { try { FXMLLoader loader

我的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'
首选宽度设置为
使用计算机大小
,突出显示的
AnchorPane的
最小宽度设置为
使用计算机大小
,首选宽度设置为
使用计算机大小
。以下是我用来解决此问题的代码:

<?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>


不要链接代码。创建一个演示问题的对话框,并将其发布到问题中。由于您不了解UI会发生什么,我建议您使用它来了解这个灰色窗格是什么。(它实际上是你众多的主播之一)。我用一个例子更新我的问题@James_D。你的问题是由于你在一些
窗格上设置的一些最小/首选值。