2014-06-14 71 views
4

的Java FX8標籤我需要與左側選項卡的標籤面板,標籤文本/圖形需要實現橫向左側臥標籤

我這樣做對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

莫非有人提醒爲什麼這個標籤不旋轉的另一個。

回答

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

+0

+1的是破解:-)專案組美麗的污穢,這樣黑客似乎有需要。並且無法使其工作:選項卡的寬度總是太小,就好像該圖形未包含在pref計算中一樣。還有什麼竅門? – kleopatra

+0

您是否指我的圖形中標籤尺寸較小或是您面臨的問題?你需要在堆棧窗格上設置大小屬性,以便它反映在Tab中,我知道它愚蠢但Ex:StackPane stp = new StackPane(new Group(l)); \t \t \t stp.setPrefHeight(160); – abacusreader

+0

意味着我試圖重現你的黑客問題:-)嗯..仍然沒有運氣。你的jdk版本是什麼? – kleopatra

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); 
相關問題