【问题标题】:Using TabPane in JavaFX在 JavaFX 中使用 TabPane
【发布时间】:2017-01-27 19:26:41
【问题描述】:

我正在从使用流程窗格切换到选项卡窗格。我不知道该怎么做。 我想在 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);
}

【问题讨论】:

    标签: java javafx tabs pane graphicscontext


    【解决方案1】:

    Tab 不是Pane 的子类,所以它没有getChildren() 方法。

    相反,它有一个content property,其值是选项卡中显示的节点(注意选项卡中只有一个节点)。

    所以你可以在标签中显示画布

    tab1.setContent(canvas);
    

    当然,如果你有两个东西要显示,你可以把它们放在其他容器中,并将标签的内容设置到容器中:

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

    【讨论】:

      猜你喜欢
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 2016-10-17
      相关资源
      最近更新 更多