Java FX8选项卡左侧带有水平选项卡

时间:2014-06-14 11:17:48

标签: javafx javafx-8

我需要一个带标签的窗格,左侧有标签,标签文字/图形需要水平

几个月前我在Scenebuilder上做过这个。

但是,当我通过Java代码添加其他选项卡时,选项卡位于左侧,但图形文本是垂直的,与使用“场景”构建器创建的选项卡不同。

在附图中,前两个选项卡是通过Scenebuilder创建的,它们的方向正确,第三个是使用Java代码动态添加的。

Tab studentAdmission = new Tab();
        studentAdmission.setContent((Parent)new FXMLLoader(getClass().getResource("Customer_View.fxml")).load());


        studentAdmission.setGraphic(new Label("Student Admission"));
        mainTab.getTabs().add(studentAdmission);

enter image description here

有人可能会建议为什么这个标签不会像另一个那样旋转。

2 个答案:

答案 0 :(得分:5)

在发布问题后,您需要添加一个包含包含标签的组的StackPane来解决这个问题。

  Tab studentAdmission = new Tab();
     studentAdmission.setContent((Parent)new FXMLLoader(getClass().getResource("Customer_View.fxml")).load());

    Label l = new Label("Student Admission");
    l.setRotate(90);
    StackPane stp = new StackPane(new Group(l));
    studentAdmission.setGraphic(stp);
    mainTab.getTabs().add(studentAdmission);

enter image description here

答案 1 :(得分:1)

    // Firstly
    tabPane.setSide(Side.LEFT);
    tabPane.setRotateGraphic(true);        

    Label l = new Label("Titel Tab1");
    l.setRotate(90);
    StackPane stp = new StackPane(new Group(l));
    stp.setRotate(90);
    tab1.setGraphic(stp);

    l = new Label("Titel Tab2");
    l.setRotate(90);
    stp = new StackPane(new Group(l));
    stp.setRotate(90);
    tab2.setGraphic(stp);

    tabPane.setTabMinHeight(100);
    tabPane.setTabMaxHeight(100);