【问题标题】:Center VBox in Pane在窗格中居中 VBox
【发布时间】:2017-01-04 13:23:06
【问题描述】:

我是 javaFx 新手并使用 fxml 创建模板。 我无法将Vbox 放在太大的Pane 中,尽管我确信它一定非常简单。 我还想要VBox 周围的边框。

有人可以帮忙吗?这是我所拥有的:

<TitledPane text="Title" collapsible="false">
     <content>
        <GridPane hgap="10" vgap="10">
           <children>
              <VBox alignment="TOP_CENTER" spacing="10">
                  <!-- Content -->
              </VBox>
           </children>
           <columnConstraints>
              <ColumnConstraints halignment="CENTER"/>
           </columnConstraints>
           <rowConstraints>
              <RowConstraints/>
           </rowConstraints>
        </GridPane>
     </content>
  </TitledPane>

我猜GridPane 是个坏主意,但这是我知道的拥有我想要的边框的方式。

感谢您的宝贵时间!

【问题讨论】:

    标签: javafx-8 fxml centering pane


    【解决方案1】:

    我猜GridPane 是个坏主意,但这是我知道的拥有我想要的边框的方式。

    是的。对一个孩子使用GridPane 是一种矫枉过正。只需使用StackPanepadding10

    <TitledPane text="Title" collapsible="false">
        <content>
            <StackPane>
                <padding>
                    <Insets topRightBottomLeft="10"/>
                </padding>
                <children>
                    <VBox alignment="TOP_CENTER" spacing="10">
                        <children>
                            <!-- Content -->
                        </children>
                    </VBox>
                </children>
            </StackPane>
        </content>
    </TitledPane>
    

    【讨论】:

    • 这确实起到了填充的作用(尽管必须分开顶部、右侧、底部和左侧),但现在包含在 Vbox 中的表格(确切地说是 TableView)占据了整个宽度(在它们之前只占用了大约 3/5 的空间,并且一直向左)。我怎样才能使它们居中?
    • @ldebroux 将fillWidth 设置为false 用于VBox
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2019-10-01
    相关资源
    最近更新 更多