[英]Using TabPane in 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);
}
Tab
不是Pane
的子類,因此它沒有getChildren()
方法。
相反,它具有content
屬性,其值是選項卡中顯示的節點(請注意,選項卡中只有一個節點)。
因此,您可以使用
tab1.setContent(canvas);
當然,如果要顯示兩件事,可以將它們放在其他容器中,然后將標簽的內容設置為該容器:
VBox vbox = new VBox(ui, canvas);
tab1.setContent(vbox);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.