2017-12-16 12 views
1

私はJavaFXプロジェクトで作業しようとしています.Gluon SceneBuilderを使用してシーンを構築していますので、時間がかかりません。私は、デフォルトのウィンドウの境界線を削除して、私自身の関数ボタン(ウィンドウを閉じる、最小化、最大化)を含めることを試みており、これらを追加するためにウィンドウの上部にButtonBarを使用していますが、何らかの理由で、私は彼らに欲しいのと同じように彼らの間隔で働いています。JavaFXシーンビルダボタンバーの間隔

間にスペースを入れずに直接並べる予定ですが、正しく動作させることはできません。私は、ボタンとボタンバーのためのすべての異なる設定とオプションを見てきましたが、そこにはどこにもマージンやパディングがありますが、見た目にはまだ間隔が空いていますhere。それらの間にスペースがないようにするにはどうすればよいですか?

+0

です。 – DVarga

+0

なぜあなたは 'Toolbar'を使わず、CSSの' -fx-spacing'プロパティを使ってカスタマイズしましたか? –

答えて

1

あなたのボタンバーを保存するための理由を持っていて、直接他のレイアウト(ツールバーやHBoxの)を使用したくない場合は、次のことができます。たとえば、この1は右上に常に3つのボタンを作成しますあなたのボタンバーにの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

1

ButtonBarの代わりにHBoxを使用できます。

<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> 
+0

しかし、ButtonBarは基本的にHBoxであり、オペレーティングシステム固有のボタン配置のための追加機能があります。 –

+0

「ボタンの特定の配置」は必要ありません。この方法でボタン(ラベル、画像)を実装しようとするだけです。ペイン(この例では)は、いくつかの要素間の単なるスペーサーです。この場合、ボタンが常に右上に表示されます – zlakad

1

ButtonBarは、あまりカスタマイズされていない特定のレイアウトをプリセットします。代わりに、GridPane、FlowPane、HBoxなどの他のレイアウトペインと組み合わせた1つまたは複数のToolBarを試してみてください。

<?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>