我正在使用 css 设计 JavaFX TabPane 组件的样式,但我无法找到实际上在选项卡周围产生额外空白的原因。有人找到了从制表符区域删除多余空间的方法吗?图片显示了我目前拥有的东西。
最佳答案
您可以通过在 CSS style sheets 中设置它们来为 JavaFX 类添加边框和边距。 .实际上,JavaFX 中的所有样式都应该这样完成。
这是Skinning JavaFX Applications with CSS的教程. 您还需要查看 JavaFX CSS Reference Guide ,其中解释了 JavaFX 可能的 CSS 元素。
您正在寻找的是“-fx-padding”。来自引用:
A sets of four padding values, separated by commas. For each item in the series, a single padding value means that all padding are the same; and if a set of four padding values is specified, they are used for the top, right, bottom, and left edges of the region, in that order.
例如,您可以通过向屏幕添加样式表来设置所有选项卡的填充:
scene.getStylesheets().add("urlpath/to/mystylesheet.css");
其中“mystylesheet.css”具有以下内容:
.tab{
-fx-padding: 0 30 0 30;
}
或者您也可以在代码中为单个元素添加样式:
Tab tabA = new Tab();
tabA.setText("Tab A");
tabA.setStyle("-fx-padding: 0 30 0 30;");
tabPane.getTabs().add(tabA);
关于JavaFX 选项卡 Pane 样式,如何删除多余的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721785/