JavaFX – how to set the margins of borderpane in fxml?
•
Java
I want 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">
<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">
<TextField fx:id="inputArea" minWidth="200" maxWidth="450" prefWidth="450"/>
<Button text="Send" onAction="#sendMessage" minWidth="200" maxWidth="450" prefWidth="450"/>
</FlowPane>
</bottom>
However, when I tried to set the margin in this way, I failed:
<ScrollPane BorderPane.margin="25,25">
I have also tried these methods:
<ScrollPane BorderPane.margin="25 25 25 25"> <ScrollPane BorderPane.margin="25">
These are all the exceptions I get:
java.lang.IllegalArgumentException: Unable to coerce 25,25 to class javafx.geometry.Insets.
This is my first time using JavaFX. I can't find any good examples Thanks for your help!
Solution
You need to add margins as child elements of the child nodes of 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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
