JavaFX之MenuItem

上图为楼楼java期末实验设计其中一部分(图文无关)



MenuItem
MenuItem is intended to be used in conjunction with Menu to provide options to users.
MenuItem serves as the base class for the bulk of JavaFX menus API.
It has a display text property, as well as an optional graphic node that can be set on it.
 The accelerator property enables accessing the associated action in one keystroke.
 Also, as with the Button control, by using the setOnAction(javafx.event.EventHandler) method,
 you can have an instance of MenuItem perform any action you wish. 
Note: Whilst any size of graphic can be inserted into a MenuItem,
the most commonly used size in most applications is 16x16 pixels.
This is the recommended graphic dimension to use if you're using the default style provided by JavaFX.
菜单项的目的就是结合菜单为用户提供选择,MenuItem为庞大的MenuAPI提供基础类的服务,MenuItem有在菜单中展示文本的属性,同时也支持图形节点代替文本展示
这个属性使得MenuItem可以关联到键盘输入(大概应该是可以监听到键盘吧,英语渣渣sorry)
MenuItem可以在Mune中像Button那样,事件处理用setOnAction方法也可以使用MenuItem自己的方法,
当使用图形节点代替MenuItem的文字显示时注意像素最好使用16px
官方例子:
MenuItem menuItem = new MenuItem("Open");
menuItem.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent e) {
        System.out.println("Opening Database Connection...");
    }
});
menuItem.setGraphic(new ImageView(new Image("flower.png")));


final Menu menu = new Menu("File");
menu.getItems().add(menuItem);












你可能感兴趣的:(学习笔记,JavaFX,menu,menuitem)