Css 带标题窗格的VBox的JavaFX填充

Css 带标题窗格的VBox的JavaFX填充,css,javafx,accordion,pane,vbox,Css,Javafx,Accordion,Pane,Vbox,因为我需要同时拥有多个可折叠的标题窗格(默认的JavaFX Accordion不支持),所以我在VBox中添加了一些标题窗格。到目前为止,这工作得很好,但我意识到标题窗格的宽度比实际VBox的宽度小10px 以下是FXML代码: <Pane prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.71" xmlns:fx="http://javafx.com/fxml/1"> <

因为我需要同时拥有多个可折叠的标题窗格(默认的JavaFX Accordion不支持),所以我在VBox中添加了一些标题窗格。到目前为止,这工作得很好,但我意识到标题窗格的宽度比实际VBox的宽度小10px

以下是FXML代码:

<Pane prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.71" xmlns:fx="http://javafx.com/fxml/1">
    <children>
        <VBox prefHeight="700.0" prefWidth="1000.0">
            <children>
                <TitledPane animated="false" text="Pane 1">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
                <TitledPane animated="false" text="Pane 2">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
            </children>
        </VBox>
    </children>
</Pane>
对我来说,这个解决方案很好,但它似乎是一个糟糕的解决办法。我想需要一个更聪明的解决方案

非常感谢:)

窗格随舞台调整大小,但VBox的宽度不超过1000px。 拍摄阶段的宽度约为1010px

您应该能够省去窗格:


或者,如果出于某种原因需要在上面安装面板,则使用AnchorPane调整vbox的尺寸:

<AnchorPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
        <VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
                <TitledPane animated="false" text="Pane 1">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
                <TitledPane animated="false" text="Pane 2">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
            </children>
        </VBox>
   </children>
</AnchorPane>

谢谢@geh:

根据场景调整舞台大小解决了问题,无需css调整:

@Override
public void start( Stage stage ) throws Exception {
    Pane root = (Pane) FXMLLoader.load( getClass().getResource( "root.fxml" ) );
    Scene scene = new Scene( root );
    stage.setScene( scene );
    stage.setResizable( false );
    // the following solved it
    stage.sizeToScene();
    stage.setTitle( "JavaFx Test" );
    stage.show();
}

谢谢,就这样!;-)
<AnchorPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
        <VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
                <TitledPane animated="false" text="Pane 1">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
                <TitledPane animated="false" text="Pane 2">
                    <content>
                        <AnchorPane prefHeight="300.0" />
                    </content>
                </TitledPane>
            </children>
        </VBox>
   </children>
</AnchorPane>
@Override
public void start( Stage stage ) throws Exception {
    Pane root = (Pane) FXMLLoader.load( getClass().getResource( "root.fxml" ) );
    Scene scene = new Scene( root );
    stage.setScene( scene );
    stage.setResizable( false );
    // the following solved it
    stage.sizeToScene();
    stage.setTitle( "JavaFx Test" );
    stage.show();
}