java 如何在 JavaFX 中仅设置顶部填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30458972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set only a top padding in JavaFX
提问by Maxoudela
I want to specify only one (or several) values for a padding using CSS in JavaFX.
我只想在 JavaFX 中使用 CSS 为填充指定一个(或多个)值。
I've read the documentation here http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typesizebut I can either specify a value for all four side of padding, or a value for each one.
我在这里阅读了文档http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typesize但我可以为所有四个边指定一个值填充,或每个值。
Is it not possible to specify, for example, my top padding and let the rest be inherited? Same goes for borders..
例如,是否无法指定我的顶部填充并让其余部分被继承?边框也是一样。。
回答by Mirza Sulji?
You will have to CSS like so
yourObject.setStyle("-fx-padding: 10 0 0 0;");
This will add padding only on the top side of your object. In CSS, the padding parameters are entered in this order: TOP, RIGHT, BOTTOM, LEFT. Clockwise.
So ie. if you wanted to add 30 padding to the left side of your object, you'd use this: yourObject.setStyle("-fx-padding: 0 0 0 30;");
You can also combine it anyway you want (top and right for example).
您将不得不像这样使用 CSS
yourObject.setStyle("-fx-padding: 10 0 0 0;");
这将仅在对象的顶部添加填充。在 CSS 中,填充参数按以下顺序输入:TOP、RIGHT、BOTTOM、LEFT。顺时针。所以即。如果您想在对象的左侧添加 30 个内边距,yourObject.setStyle("-fx-padding: 0 0 0 30;");
您可以使用这个:您也可以随意组合它(例如顶部和右侧)。
回答by Smaillns
you can edit it easly with sceneBuilder
您可以使用sceneBuilder轻松编辑它
so if you want to edit the padding with your code java (in particular when you make an interanl class ) you can simply call the function setPadding()
, ok!. But if you want to set the margin you have to do that throught the parent layout because it's not internal properties .. ==> [your element_parent_layout].setMargin([your element], new Insets([top],[right],[bottom],[left]));
所以如果你想用你的代码 java 编辑填充(特别是当你创建一个内部类时)你可以简单地调用函数setPadding()
,好的!。但是如果你想设置边距,你必须通过父布局来做,因为它不是内部属性.. ==>[your element_parent_layout].setMargin([your element], new Insets([top],[right],[bottom],[left]));
sorry for this quick answer .., if you have any problem you can ask me ;)
抱歉这么快回答..,如果您有任何问题,可以问我;)