JavaFX:如何定义边距到CSS中的TextField? [英] JavaFX: How to define margin to TextField in css?

查看:1651
本文介绍了JavaFX:如何定义边距到CSS中的TextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用CSS在JavaFX中为 TextField 定义填充和边距?我试过 -fx-padding 和一些其他属性,但没有效果。我使用JavaFX 2.2,它包括在最新版本的Java 7中。

Is it possible to define padding and margin for TextFields in JavaFX using CSS? I have tried -fx-padding and some other properties, but no effect. I am using JavaFX 2.2 which is included in the latest version of Java 7.

我有很多文本字段,并做类似的操作:

I have many textfields and doing something like:

    <GridPane.margin>
        <Insets bottom="10.0" left="60.0" right="0.0" top="10.0"/>
    </GridPane.margin>

每个文本字段对我来说不是一个好的解决方案。

after each textfield is not a good solution for me.

推荐答案

通过java fx css 为单个元素配置边距

没有-fx-margin:5px javafx textfields的css属性,但你可以用padding,border-insets和background-insets的组合来解决这个行为。

Theres no -fx-margin:5px css property for javafx textfields, but you can workaround the behaviour with a combination of padding, border-insets and background-insets.

例如一个文本字段,边距为5px。

For example a text-field with a 5px margin.

.text-field-with-margin {
    -fx-padding: 5px;
    -fx-border-insets: 5px;
    -fx-background-insets: 5px;
}

或者,您还可以定义更高的填充和更低的插入值填充和边距。

Alternatively you can also define a higher padding and lower insets values in case you want a padding and a margin.

这篇关于JavaFX:如何定义边距到CSS中的TextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆