尽管指定了USE_COMPUTED_SIZE,JavaFX和Scene Builder剪辑了场景边缘

Bob*_*ous 6 java javafx fxml scenebuilder

I'm using Scene Builder (v11.0.0) to create FXML files for scenes in JavaFX (v12) but, despite instructing all containers to USE_COMPUTED_SIZE for the preferred widths and heights, the rendered scenes (as seen in Scene Builder and also when run as a JavaFX application which loads those FXML files) are being clipped at the right and bottom edges so that bits of nodes are chopped off.

And in Scene Builder it seems that the renderer must know that the scene won't fit the allowed bounds because the editor shows blue boundary markers which are clearly some way beyond the rendered rectangle.

View in Scene Builder

Scene Builder中视图的屏幕截图,显示了窗体设计已在右侧和底部边缘被剪切,然后是显示内容应位于何处的深色边界,然后是显示该边界范围的蓝色边界标记。

The view in Scene Builder shows that more space is needed at the bottom in order to give the buttons sufficient space (their bottom edge, and the lower edge of the TitledPane is missing). And more space is needed at the right in order to fit the right edges of the DatePicker and TitledPane. The blue boundary markers show clearly where the actual content ends, so it's not clear why the display area is being calculated to be several pixels shorter than this.

View of running Java application

Screenshot of the scene rendered within a Java application, the form design clipped at the right and bottom edges, very similar to the degree of clipping seen in Scene Builder.

Once the FXML files are used to populate a window in a JavaFX application, the same thing is seen: the calculated size for the window is a number of pixels too few to fit the whole scene correctly.

If the blue boundary markers have correctly been calculated to show that extra display area width and height are needed, how do I tell the FXML to require this additional space when rendering?

Is this a known bug/limitation in Scene Builder, FXML, or JavaFX. Or is there something more I need to do beyond just selecting USE_COMPUTED_SIZE for the preferred dimensions?

In order to make this explicit, see the example FXML below which displays the problem illustrated.

scene.fxml

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TitledPane animated="false" collapsible="false" text="untitled">
        <content>
            <HBox>
               <children>
                  <fx:include source="subscene.fxml" />
               </children>
            </HBox>
        </content>
      </TitledPane>
      <TitledPane animated="false" collapsible="false" text="untitled">
        <content>
            <HBox>
               <children>
                  <fx:include source="subscene.fxml" />
               </children>
            </HBox>
        </content>
      </TitledPane>
      <TitledPane animated="false" collapsible="false" text="untitled">
        <content>
            <HBox alignment="BASELINE_RIGHT">
               <children>
                  <Button mnemonicParsing="false" text="Button" />
                  <Button mnemonicParsing="false" text="Button" />
               </children>
            </HBox>
        </content>
      </TitledPane>
   </children>
</VBox>
Run Code Online (Sandbox Code Playgroud)

subscene.fxml

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

<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Label text="Label" />
      <DatePicker />
   </children>
</VBox>
Run Code Online (Sandbox Code Playgroud)

Sla*_*law 3

这似乎确实是 JavaFX 中的一个错误,具体来说DatePicker,因为这个简单的示例可以重现该问题:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {   
        VBox root = new VBox(new DatePicker());

        // Problem shows up when using USE_COMPUTED_SIZE (the default) as well
        root.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
        root.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);

        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

}
Run Code Online (Sandbox Code Playgroud)

导致:

显示尺寸不正确的日期选择器父级的图像

注意:放置在哪个父控件中似乎并不重要DatePicker。其他控件也不会出现该问题。

此问题的解决方法似乎是Window.sizeToScene()在调用后调用show()。我不明白为什么这会有所不同,但确实如此。不幸的是,这仅对实际应用程序有帮助,而对场景生成器没有帮助。