fxml
fxml
<TabPane layoutX="0.0" layoutY="0.0" prefHeight="707.0" prefWidth="1000.0" rotateGraphic="true" side="LEFT" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="deviceTab">
<content>
</content>
</Tab>
<tabs>
</TabPane>
Controller.java
java
public Tab deviceTab;
@Override
public void initialize(URL location, ResourceBundle resources) {
// 插入文字到tab上
deviceTab.setGraphic(this.markLeftTabGroup("设备调试"));
}
/**
* 生成倒排旋转文字
*/
public Group markLeftTabGroup(String text) {
char[] split = text.toCharArray();
Group group = new Group();
group.setAutoSizeChildren(true);
int length = split.length;
for (int i = 0; i < length; i++) {
// 走最后一个字开始, 最后的字会排在最前面
String c = String.valueOf(split[length - i - 1]);
Label label = new Label(c);
// 设置位置
label.setLayoutX(13 + 13 * i);
// 旋转90度
label.setRotate(90);
group.getChildren().add(label);
}
return group;
}
效果: