javafx fxml之右键菜单

时间:2021-12-06 14:30:04

要说这fxml语法有点奇特,在控件中加入右键菜单的代码如下

        <TreeView fx:id="foldertree" GridPane.rowIndex="2" GridPane.columnIndex="0"  GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
            <contextMenu>
                <ContextMenu >
                    <items><MenuItem text="ss" /></items>
                </ContextMenu>
            </contextMenu>
        </TreeView>

必须要嵌套两个contextmenu 一个首字母小写一个首字母大写,真是奇怪。