How to set only a top padding in JavaFX

给你一囗甜甜゛ 提交于 2019-12-23 10:10:57

问题


I want to specify only one (or several) values for a padding using CSS in JavaFX.

I've read the documentation here http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typesize but I can either specify a value for all four side of padding, or a value for each one.

Is it not possible to specify, for example, my top padding and let the rest be inherited? Same goes for borders..


回答1:


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




回答2:


you can edit it easly with 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]));

sorry for this quick answer .., if you have any problem you can ask me ;)



来源:https://stackoverflow.com/questions/30458972/how-to-set-only-a-top-padding-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!