加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

javafx – 如何在fxml中设置BorderPane的边距?

发布时间:2020-12-15 04:34:30 所属栏目:Java 来源:网络整理
导读:我想在 javafx中运行这个fxml代码: 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=
我想在 javafx中运行这个fxml代码:

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

但是,当我尝试以这种方式设置边距时失败:

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

我也试过这些方法:

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

这是我得到的所有例外:

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

这是我第一次使用JavaFX,我找不到任何好的例子.谢谢你的帮助!

解决方法

您需要将边距添加为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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读