JavaFX场景生成器按钮栏间距

问题描述 投票:1回答:3

我正在尝试JavaFX项目,我正在使用Gluon SceneBuilder来帮助我构建我的场景,所以它不需要这么长时间。我正在删除默认的窗口边框并尝试包含我自己的功能按钮(关闭窗口,最小化,最大化),我在窗口顶部使用ButtonBar添加这些按钮,但由于某种原因,按钮不是'像我想要的那样使用它们的间距。

我打算将它们全部直接放在一起,两者之间没有任何空间,但我无法让它正常工作。我已经查看了按钮以及按钮栏的所有不同设置和选项,并且没有任何地方可以说它们中的任何一个都有边距或填充,但是它们仍然会间隔开来,因为你可以看到here。我怎样才能使它们之间没有间距?

javafx javafx-8
3个回答
1
投票

如果您有理由保存按钮栏并且不想直接使用其他布局(工具栏或HBox),则可以将Hbox添加到按钮栏并将按钮添加到您的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>

结果是enter image description here


2
投票

您可以使用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>

2
投票

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>
© www.soinside.com 2019 - 2024. All rights reserved.