2016-07-06 32 views
1

FXML佈局空間的工具欄元素ChatbotView.fxmlJavaFX的:試圖均勻地FXML

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

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.TextField?> 
<?import javafx.scene.control.ToolBar?> 
<?import javafx.scene.layout.BorderPane?> 
<?import javafx.scene.text.Font?> 

<BorderPane id="background" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="706.0" stylesheets="@ChatbotStyle.css" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> 
    <top> 
     <ToolBar prefHeight="40.0" prefWidth="200.0" styleClass="spacer" BorderPane.alignment="CENTER"> 
     <items> 
      <Button mnemonicParsing="false" text="Calendar"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Topic List"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <TextField> 
       <font> 
        <Font size="14.0" /> 
       </font></TextField> 
      <Button mnemonicParsing="false" text="Chatbot's Button"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Quit"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
     </items> 
     </ToolBar> 
    </top> 
    <bottom> 
     <ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER"> 
     <items> 
      <Button mnemonicParsing="false" text="Map"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Load from File"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Save to File"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Send Tweet"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
      <Button mnemonicParsing="false" text="Search Twitter"> 
       <font> 
        <Font size="14.0" /> 
       </font></Button> 
     </items> 
     </ToolBar> 
    </bottom> 
</BorderPane> 

我只是想弄清楚如何均勻地空間中的所有工具欄元素,因此最終看起來是這樣的:

enter image description here

在此先感謝。

回答

2

只是覆蓋CSS樣式的工具欄:

.tool-bar { /* top */ 
    -fx-alignment: CENTER; 
} 

或者只是把它直接在FXML:

<ToolBar style="-fx-alignment: CENTER" ...> 
+0

謝謝! CSS代碼的變化絕對沒有辦法。 –