TabPane中的按钮使用JavaFX

时间:2016-08-29 11:31:20

标签: java javafx javafx-8

在JavaFX 8中是否有办法将按钮放入TabPane,如下面的模型所示?如果可能,我只想使用FXML文件。 mockup

2 个答案:

答案 0 :(得分:3)

在查看" Add Buttons to Tabs and Tab area JavaFX"的问题和答案之后,对它进行调整并不困难,因为它适用于FXML文件。

<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mypackage.Controller">
    <children>
        <TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.topAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.bottomAnchor="0.0">
            <tabs>
                /* the code for the tabs goes here */
            </tabs>
        </TabPane>
        <HBox AnchorPane.topAnchor="1.0" AnchorPane.rightAnchor="5.0">
            <children>
                <Button text="Export..." />
                <Button text="Generate" />
            </children>
        </HBox>
    </children>
</AnchorPane>

结果如下图所示。

enter image description here

答案 1 :(得分:2)

几个月前,只有几个星期的场景构建工作和FXML文件的应用程序,我尝试做类似的事情,但我没有成功尝试这样做,因为我认为如果你想添加一些标签,顶部的空间是保留的,我解决了我在插入所需标签的问题我会在那里的按钮,这里是我做的一个例子: enter image description here

我希望它对你也有用