5

I am trying to run this fxml code in javafx:

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

However, it fails when I try to set the margin this way:

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

I have also tried these methods:

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

This is the exception I get with all of them:

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

This is my first time using JavaFX and I couldn't find any good examples of this. Thanks for any help!

fabian
  • 80,457
  • 12
  • 86
  • 114
zephos2014
  • 331
  • 1
  • 2
  • 13

1 Answers1

11

You need to add the margin as subelement of the child node of the 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>
fabian
  • 80,457
  • 12
  • 86
  • 114