JavaFX Scene Builder 按钮栏间距

JavaFX Scene Builder Button Bar Spacing

我正在尝试处理一个 JavaFX 项目,我正在使用 Gluon SceneBuilder 来帮助我构建我的场景,所以不会花那么长时间。我正在删除默认的 window 边框并尝试包含我自己的功能按钮(关闭 window、最小化、最大化)并且我在 window 顶部使用 ButtonBar 来添加这些在里面,但出于某种原因,按钮没有像我希望的那样按照它们的间距工作。

我打算将它们直接并排放置,中间没有 space,但我无法使其正常工作。我查看了按钮和按钮栏的所有不同设置和选项,但没有任何地方说其中任何一个都有边距或填充,但它们仍然 spaced如您所见 here。我怎样才能使它们之间没有间距?

您可以使用 HBox 而不是 ButtonBar。像这样:

 <HBox prefHeight="30.0" prefWidth="600.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
     <children>
        <Pane HBox.hgrow="ALWAYS" />
        <Button text="Button" />
        <Button text="Button" />
        <Button text="Button" />
     </children>
  </HBox>

ButtonBar预设了一定的布局,应该不是很定制。尝试将一个或多个 ToolBar 与其他布局面板(如 GridPane、FlowPane 或 HBox)结合使用。例如这个总是在右上角创建 3 个按钮:

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>

<BorderPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <top>
      <GridPane>
         <columnConstraints>
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints halignment="RIGHT" hgrow="NEVER" minWidth="10.0" />
         </columnConstraints>
         <rowConstraints>
            <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
         </rowConstraints>
         <children>
            <ToolBar prefHeight="30.0" GridPane.halignment="RIGHT" GridPane.valignment="TOP" />
            <ToolBar prefHeight="30.0" style="-fx-padding: 0;" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.valignment="TOP">
               <items>
                  <HBox>
                     <children>
                        <Button mnemonicParsing="false" style="-fx-margin: 0;" text="Button" />
                        <Button mnemonicParsing="false" text="Button" />
                        <Button mnemonicParsing="false" style="margin: 0;" text="Button" />
                     </children>
                  </HBox>
               </items>
            </ToolBar>
         </children>
      </GridPane>
   </top>
</BorderPane>

如果你有理由保存你的按钮栏并且你不想直接使用其他布局(工具栏或 HBox),你可以添加一个 Hbox 到你的 Button Bar 并像这样将你的按钮添加到你的 hbox :

<ButtonBar buttonOrder="L_HE+U+FBIX_NCYOA_T" layoutX="130.0" layoutY="24.0" prefHeight="0.0" stylesheets="@fx.css" ButtonBar.buttonData="APPLY">
    <buttons>
        <HBox>
           <children>
              <Button mnemonicParsing="false" text="Button" HBox.hgrow="ALWAYS" />
            <Button mnemonicParsing="false" text="Button" HBox.hgrow="ALWAYS" />
              <Button mnemonicParsing="false" text="Button" />
              <Button mnemonicParsing="false" text="Button" />
              <Button mnemonicParsing="false" text="Button" />
           </children>
        </HBox>
    </buttons>
  </ButtonBar>

结果是