Java GUI – Creating Menu Button in JavaFX

In this Java GUI article we are going to learn Creating Menu Button in JavaFX, so MenuButton

 is a button which, when clicked or pressed, will show a ContextMenu . a MenuButton shares a

very similar API to the Menu control, so for that you set the items that should be shown in

the items ObservableList, and there is a Labeled. text property to specify the label shown within

the MenuButton.

 

 

 

Also you can check Python GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

5: wxPython GUI Development Tutorials

 

 

 

 

 

You can create Menu Button by creating the object of MenuButton class like this.

you need to give the text for the MenuButton, an image and also the items that you want to

add in this MenuButton.

 

 

 

 

So now this is the source code for Java GUI – Creating Menu Button in JavaFX

 

 

 

 

These are the menu items that we need to for the MenuButton, basically there are four

menu items that we want.

 

 

 

 

This is the image that we want to add for the JavaFX MenuButton, make sure that you have

already added an icon in your working directory.

 

 

 

 

 

 

In every JavaFX application we need to create a container,  a container is like layout. as we

have created an HBox container in the above code, and we add our MenuButton object in the 

HBox Layout.

 

 

 

 

Also for every JavaFX application we need to create a Scene object. in the scene we need

to add our container with the width and height of the window, if you want to colorize your

window, you can do it in here. you can see that we have given 400 width and 300 height for the

window.

 

 

 

 

At the end you need to set your scene object to the stage of the window, and show the window.

 

 

 

 

Run the complete code and this will be the result 

Java GUI – Creating Menu Button in JavaFX
Java GUI – Creating Menu Button in JavaFX

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×