2016-06-07 48 views
2

我試圖運行JavaFX的這個FXML代碼:如何在fxml中設置BorderPane的邊距?

<ScrollPane BorderPane.margin="25, 25, 25, 25"> 

我也曾嘗試這些:

<BorderPane fx:controller="com.bryantmorrill.chat.main.Controller" 
     xmlns:fx="http://javafx.com/fxml" > 

<center> 
    <ScrollPane BorderPane.margin="25, 25, 25, 25"> 
     <content> 
      <TextArea fx:id="chatArea" minWidth="200" maxWidth="450" 
         prefWidth="450" minHeight="200" prefHeight="400" 
         maxHeight="400"/> 
     </content> 
    </ScrollPane> 
</center> 

<bottom> 
    <FlowPane BorderPane.margin="25, 25, 25, 25"> 
     <TextField fx:id="inputArea" minWidth="200" maxWidth="450" prefWidth="450"/> 
     <Button text="Send" onAction="#sendMessage" minWidth="200" maxWidth="450" prefWidth="450"/> 
    </FlowPane> 

</bottom> 

然而,當我嘗試設置margin這種方式失敗方法:

<ScrollPane BorderPane.margin="25 25 25 25"> 
<ScrollPane BorderPane.margin="25"> 

這是我得到的所有異常他們:

java.lang.IllegalArgumentException: Unable to coerce 25, 25, 25, 25 to class javafx.geometry.Insets. 

這是我第一次使用JavaFX,我找不到任何這樣的好例子。謝謝你的幫助!

回答

5

您需要保證金添加爲BorderPane的子節點的子元素:

<center> 
    <ScrollPane> 
     <BorderPane.margin> 
      <Insets bottom="25.0" left="25.0" right="25.0" top="25.0" /> 
     </BorderPane.margin> 
     <content> 
      <TextArea fx:id="chatArea" minWidth="200" maxWidth="450" 
         prefWidth="450" minHeight="200" prefHeight="400" 
         maxHeight="400"/> 
     </content> 
    </ScrollPane> 
</center> 
<bottom> 
    <FlowPane> 
     <BorderPane.margin> 
      <Insets bottom="25.0" left="25.0" right="25.0" top="25.0" /> 
     </BorderPane.margin> 
     <TextField fx:id="inputArea" minWidth="200" maxWidth="450" prefWidth="450"/> 
     <Button text="Send" onAction="#sendMessage" minWidth="200" maxWidth="450" prefWidth="450"/> 
    </FlowPane> 
</bottom> 
+0

謝謝!這正是我所需要的。 – zephos2014