2017-01-27 62 views
0

我正在從使用流程面板切換到Tabpane。我不知道如何。 我想在tabpane內使用畫布和窗格,這可能嗎? 下面是沒有所有的造型我的代碼等在JavaFX中使用TabPane

public View(TabPane root) { 
    this.root = root; 

    tab1 = new Tab(); 
    root.getTabs().add(tab1); 

    tab2 = new Tab(); 
    root.getTabs().add(tab2); 

    ui = new Pane(); 

    canvas = new Canvas(600,600); 
    //gc is graphics context 
    gc = canvas.getGraphicsContext2D(); 

    //this is where the problem is?? 
    //i have no idea how to add ui and canvas to my tab1 
    tab1.getChildren().addAll(ui, canvas); 
} 

回答

0

Tab不是Pane子類,因此它沒有getChildren()方法。

相反,它有一個content property,它的值是選項卡中顯示的節點(請注意,選項卡中只有一個節點)。

所以,你可以用

tab1.setContent(canvas); 

顯示的標籤中的畫布,當然,如果你有兩件事情來顯示的,你可以把它們放在一些其他的容器,並設置選項卡的內容在容器:

VBox vbox = new VBox(ui, canvas); 
tab1.setContent(vbox);