Add Images to Menu Items
You can add images to menu items or use images instead of text. The easiest way to add an image is to specify it when the menu item is being constructed using this constructor:
MenuItem(String name, Node image)
It creates a menu item with the name specified by name and the image specified by image. For example, here the About menu item is associated with an image when it is created.
ImageView aboutIV = new ImageView("aboutIcon.gif");
MenuItem about = new MenuItem("About", aboutIV);
After this addition, the image specified by aboutIV will be displayed next to the text “About” when the Help menu is displayed, as shown here:
One last point: You can also add an image to a menu item after the item has been created by calling setGraphic( ). This lets you change the image during program execution.
Copyright © 2018-2021 BrainKart.com; All Rights Reserved. (BS) Developed by Therithal info, Chennai.