How to set tab name size in JavaFX

风格不统一 提交于 2019-12-06 12:33:37

You can do it through CSS. Create a "myStyle.css" file in your project and override the default CSS selector of the tab label by pasting the following into this css file:

.tab .tab-label {
    -fx-skin: "com.sun.javafx.scene.control.skin.LabelSkin";
    -fx-background-color: transparent;    
    -fx-alignment: CENTER;
    -fx-text-fill: -fx-text-base-color;
    -fx-font-size: 8px; /* all the same except this newly added one */
}

This css is originally copied from caspian.css. For more customization use -fx-font and/or refer to JavaFX CSS Reference Guide.

Load the css file into the scene.

scene.getStylesheets().add(this.getClass().getResource("myStyle.css").toExternalForm());

or into the tabPane directly,

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