2016-06-07 454 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