Home | | Web Programming | Add Images to Menu Items - JavaFX

Chapter: Java The Complete Reference : Introducing GUI Programming with JavaFX : Introducing JavaFX Menus

Add Images to Menu Items - JavaFX

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:

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.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Java The Complete Reference : Introducing GUI Programming with JavaFX : Introducing JavaFX Menus : Add Images to Menu Items - JavaFX |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.