Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the margin of a BorderPane in fxml?

Tags:

javafx

fxml

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!

like image 582
zephos2014 Avatar asked Jan 05 '23 22:01

zephos2014


1 Answers

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>
like image 138
fabian Avatar answered Feb 25 '23 02:02

fabian